Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Tasks: Follow the directions below to complete your lab assignment For today's lab we will be completing Exercise P9.1 from the book (with modifications/additions). Book

Tasks: Follow the directions below to complete your lab assignment

For today's lab we will be completing Exercise P9.1 from the book (with modifications/additions). Book = Big Java

P9.1 Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, see the dentist) and a date (use int's to store the date). Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. (Think about what you need to check for the other types of appointments. Ask if you have questions).

(Skip the remaining problem description listed in the book, and follow these directions below).

Additionally, you will need to implement a class called Calendar. This will contain an ArrayList of Appointment objects (The list is an instance variable of the Calendar class). You will need to provide the following methods for your Calendar class.

A no argument constructor

public Calendar(){...}

This constructor will initialize your ArrayList instance variable to an empty list.

/**

* A method to add an appointment to the calendar

* @param apt the appointment object to add to the calendar.

*/

public void add(Appointment apt) {}

/**

* A method to remove an appointment from the calendar.

* This method uses the occursOn() method from the public

* interface for the Appointment class. Therefore, if parameters

* are entered that occur after a start date for a given Daily

* appointment

* the Daily appointment will be removed as well. (Because occursOn() * willreturn true in this case). This is a limitation we will

* accept for now.

* @param year - the year of the appointment to remove

* @param month - the month of the appointment to remove

* @param day - the day of the appointment to remove

*/

public void remove(int year, int month, int day) {

//this method needs to iterate over your list of appointments

//and remove elements who's occursOn() method return true

//when passed the parameters above.

}

/**

* Method to return a string representation of this Calendar object.

* Overrides the Object method toString (see page 448 in text).

* (also see page 453 Special Topic 9.6)

* @return a String representation of the Calendar object.

*/

public String toString() {

String ret = "";

//this method needs to iterate over your list of appointments

//and construct the return string

//make sure to put each appointment on its own line

//by using

return ret;

}

Note that you also need to create a toString method for your Appointment class. (Your subclasses will inherit this version of the method).

Make sure to add accessors to your Appointment class for getYear, getMonth, getDay, and getDescription.

Here is some sample output from a working project using the AppointmentDemo.java.txt file posted on UTC Learn. You will need to create additional tests to prove that your project works correctly.

Before removal of appointment Daily[Brush your teeth. Date: 8/13/2000] Monthly[Visit grandma. Date: 5/20/2003] Onetime[Dentist appointment. Date: 11/2/2004] Onetime[Trick or Treat. Date: 10/31/2004] Monthly[Dentist appointment. Date: 11/2/2004] Onetime[Dentist appointment. Date: 11/2/2004]

After removal of 11/2/2004 Monthly[Visit grandma. Date: 5/20/2003] Onetime[Trick or Treat. Date: 10/31/2004]

/** * Demonstration of the Calendar and Appointment classes */ public class AppointmentDemo { public static void main(String[] args) { Calendar calendar = new Calendar(); //create some appointments and add them to our calendar //note the method calls here imply that //your Appointment class will need to have a 4 argument constructor //that accepts year, month, day, and description //the first call is year:2000, month: 8, day: 13 calendar.add(new Daily(2000, 8, 13, "Brush your teeth.")); calendar.add(new Monthly(2003, 5, 20, "Visit grandma.")); calendar.add(new Onetime(2004, 11, 2, "Dentist appointment.")); calendar.add(new Onetime(2004, 10, 31, "Trick or Treat.")); calendar.add(new Monthly(2004, 11, 2, "Dentist appointment.")); calendar.add(new Onetime(2004, 11, 2, "Dentist appointment.")); //note here we can simply use + calendar because we have //implemented the toString() method System.out.println("Before removal of appointment " + " " + calendar); calendar.remove(2004, 11, 2); //note that the daily appointment is removed because it occurs on //11/2/2004 (as well as many other days). System.out.println("After removal of 11/2/2004 " + " " + calendar); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago