Question

Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...

Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will have four instance variables: • An instance variable called “year” which will be of type int • An instance variable called “month” which will be of type int • An instance variable called “day” which will be of type int • An instance variable called “description” which will be of type String The “Appointment” class must also implement the following methods: • A getter and setter for each of the four instance variables • An abstract method named occursOn which returns a boolean and takes three parameters of type int: aYear, aMonth, aDay • Overrides the toString method from the Object superclass which returns the String: "Appointment: aDescription On Date: 1/1/1969" where, “aDescription” is the value stored in the description instance variable and “1/1/1969” are the values stored in the month, day, and year instance variables respectively. • Overrides the equals method from the Object superclass which takes a single parameter of type “Object” and returns true if the given objects is an “Appointment” object and it’s year, month, and day instance variables are equal to the current objects instance variables. If the given parameter is null, equals should return false. Create a class “Onetime” which subclasses the “Appointment” class. The “Onetime” class will define no new instance variables. Write a parameterized constructor which takes three parameters of type int: aYear, aMonth, aDay. The parameterized constructor sets the “year”, “month”, and “day” instance variables defined in the “Appointment” class to the values passed as parameters. The parameterized constructor should set the “description” instance variable to an empty String. ("") The “Onetime” class must also implement the following methods: • It must implement the abstract method “occursOn” defined in the “Appointment” class. “occuresOn” should return true if the given parameters match the year, month, and day instance variables for the object. Otherwise it should return false. Create a class “Yearly” which subclasses the “Appointment” class. The “Yearly” class will define no new instance variables. Write a parameterized constructor which takes two parameters of type int: aMonth and aDay. The parameterized constructor sets the “month” and “day” instance variables defined in the “Appointment” class to the values passed as parameters. The parameterized constructor should set the “description” instance variable to an empty String. ("") The “Yearly” class must also implement the following methods: • It must implement the abstract method “occursOn” defined in the “Appointment” class. “occuresOn” should return true if the given parameters match the month and day instance variables for the object. (We can ignore the aYear parameter because this event repeats yearly so every value is correct) Otherwise it should return false. • Overrides the toString method from the Object superclass which returns the String: "Appointment: aDescription Every Year On 1/1" where, “aDescription” is the value stored in the description instance variable and “1/1” are the values stored in the month and day instance variables respectively. Create a class “Monthly” which subclasses the “Appointment” class. The “Monthly” class will define no new instance variables. Write a parameterized constructor which takes one parameter of type int: aDay. The parameterized constructor sets the “day” instance variable defined in the “Appointment” class to the value passed as a parameter. The parameterized constructor should set the “description” instance variable to an empty String. ("") The “Monthly” class must also implement the following methods: • It must implement the abstract method “occursOn” defined in the “Appointment” class. “occuresOn” should return true if the given parameters match the day instance variable for the object. (We can ignore the aYear and aMonth parameters because this event repeats monthly so every value is correct) Otherwise it should return false. • Overrides the toString method from the Object superclass which returns the String: "Appointment: aDescription Every Month On 1" where, “aDescription” is the value stored in the description instance variable and “1” is the values stored in the day instance variable respectively.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Appointment.Java

public abstract class Appointment {
    private int year,month,day;
    private String description;
//Getters
    public void setDescription(String description) {
        this.description = description;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public void setMonth(int month) {
        this.month = month;
    }
//Setters
    public int getYear() {
        return year;
    }

    public String getDescription() {
        return description;
    }

    public int getMonth() {
        return month;
    }

    public int getDay() {
        return day;
    }
    //abstract method
    public abstract boolean occursOn(int aYear,int aMonth,int aDay);

    @Override
    public String toString() {
        return description+" "+ month+"/"+day+"/"+year;
    }

    @Override
    public boolean equals(Object obj) {
        // If the object is compared with itself then return true
        if(obj ==this)
            return  true;
        /* Check if o is an instance of Appointment or not
          "null instanceof [type]" also returns false */
        if(!(obj instanceof Appointment))
            return false;
        //typecast obj to Appointment so that we can compare data members
        Appointment appointment = (Appointment)obj;
        //Compare the data members and return accordingly
        return Integer.compare(month,appointment.month)==0
                && Integer.compare(day,appointment.day)==0
                && Integer.compare(year,appointment.year)==0;
    }
}

//OneTime.Java

public class OneTime extends Appointment {

public OneTime(int aYear,int aMonth,int aDay){
   setDay(aDay);
   setMonth(aMonth);
   setYear(aYear);
   setDescription("");
}
    @Override
    public boolean occursOn(int aYear, int aMonth, int aDay) {
    if(getDay()==aDay && getMonth()==aMonth )
        return true;
    else
        return false;
    }

    @Override
    public String toString() {
        return "Appointment: "+getDescription()+" Every year on "+getMonth()+"/"+getDay();
    }
}

//Monthly.Java

public class Monthly extends Appointment {
    public Monthly(int aDay)
    {
        setDay(aDay);
        setDescription("");
    }

    @Override
    public boolean occursOn(int aYear, int aMonth, int aDay) {
        if(aDay==getDay())
            return true;
        else
        return false;
    }

    @Override
    public String toString() {
        return "Appointment: "+ getDescription()+" Every month on "+getDay();
    }
}

//Main.java

public class Main {

    public static void main(String[] args) {
   // write your code here
        Appointment oneTime= new OneTime(2018,10,02);
      Appointment monthly = new Monthly(4);
        System.out.println(oneTime);
        System.out.println(monthly);

    }
}

//Output

C:\Program Files\Javaljdk1.8.0 92 binljava... Appointment: Every year on 10/2 Appointment: Every month on 4 : Every year on

//If you need any help regarding this question please leave a comment........... thanks

Add a comment
Know the answer?
Add Answer to:
Create an abstract class “Appointment” that represents an event on a calendar. The “Appointment” class will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has...

    Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has a description (for example "see the dentist") and a 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, check whether the day of the month matches. Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want...

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

  • Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An...

    Write a Java program that implements a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a date. It writes a method occursOn (int year, int month, int day) that checks whether the appointmentoccurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then it will fill an array of Appointment objects with a mixture of appointments. When the user...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • (JAVA) In this assignment, you will implement a superclass Appointment and subclasses Onetime, Daily, and Monthly....

    (JAVA) In this assignment, you will implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, “see the dentist”) and a 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 mon.th matches. In your application part, fill an array of Appointment objects with a mixture of appointments. Have the...

  • The Java class called Holiday is started below. An object of class Holiday represents a holiday...

    The Java class called Holiday is started below. An object of class Holiday represents a holiday during the year. This class has three instance variables: name, which is a String representing the name of the holiday day, which is an int representing the day of the month of the holiday month, which is a String representing the month the holiday is in public class Holiday { private String name; private int day; private String month; // your code goes here...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT