Question
Question 1: Java Classes, Inheritance and Polymorphism [CLO1, CLO2] Design an abstract class called Appointment that has the following fields: description of String type date
Question 1: Java Classes, Inheritance and Polymorphism [CLO1, CLO2]
Design an abstract class called Appointment that has the following fields:
- description of String type
- date of String type
The Appointment class has an abstract method called: occursOn(int year, int month, int day, int hours, int minutes)
1) Provide the following constructors:
- Full-argument constructor
- No-argument constructor that must call the full argument constructor with default values
- Copy constructor that takes as the input an object of type Appointment and creates another object having same data.
2) Provide getter and setter methods for the two fields of the Appointment class:
3) Override the toString() method to return the following message:
See dentist on 25 May 2021
when See dentist is stored in the description field and the date field is set to 25 May 2021 @ 10:00 AM.
4) Override the equals() method to return true if the current object has the same description and date fields as the passed argument and false otherwise.
5) Make sure that the Appointment class implements the Comparable interface. The compareTo() returns the sum of the differences between the description and date fields.
Hint: Remember that the String classes has its own implementation of the Comparable interface.
6) Design a class called Onetime that will extend the Appointment class that will represent non-recurrent appointments. Override the occursOn() method to check whether the appointment occurs on the given date.
7) Design a class called Daily that will extend the Appointment class that will represent daily appointments. Override the occursOn() method to check whether the appointment occurs on the given date.
Hint: The date field in the Daily class will be initialized using hours and minutes only.
8) Design a class called Monthly that will extend the Appointment class that will represent monthly appointments. Override the occursOn() method to check whether the appointment occurs on the given date.
Hint: The date field in the Monthly class will be initialized using day, hours and minutes only.
9) Write a test class that will read a list of appointments from a text file called appointments.txt. The structure of the file is shown below:
Meet Dentist#25 May 2021#12:45 PM
See Client#25#10:00 AM
Meet Your Manager#09:00 AM
Then, fill an array of Appointment objects with the list of appointments stored in the file. Finally, the number of Onetime, Daily, Monthly appointments in the file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started