1.3-Object-Georienteerd-Programmeren

Calendar

In this assignment we are going to build a calendar. The schedule can store appointments. Each appointment consists of a title and a date on which it takes place. There are three different types of appointments:

Create classes to model the above problem. Also build a method occursOn(LocalDate compareDate) that indicates of a given date whether the appointment will take place on that day. For each class, create a toString() method that transparently displays the details of the appointment.

Then implement the given Calendar class and test if your code works correctly.

Hint: use the YearMonth and the LocalDate classes from Java to determine the first day of the week and the length of the month.

Note: You should start off simple and just print out the appointments for each date.

Example main method

Feel free to use our main method to test your application! This application however does not test everything from the calendar class.

public static void main(String[] args) {
    Calendar calendar = new Calendar();

    // Create some single appointments
    calendar.addAppointment(new SingleAppointment(LocalDateTime.of(2021, 4, 10, 12, 15), "Visit the dentist"));
    calendar.addAppointment(new SingleAppointment(LocalDateTime.of(2021, 3, 22, 9, 00), "Databases exam"));
    calendar.addAppointment(new SingleAppointment(LocalDateTime.of(2021, 1, 20, 15, 00), "Retake Introduction to Programming"));

    // Create some monthly appointments
    calendar.addAppointment(new MonthlyAppointment(LocalDateTime.of(2021, 2, 25, 9, 00), "Receive student finance from DUO"));
    calendar.addAppointment(new MonthlyAppointment(LocalDateTime.of(2021, 2, 1, 20, 00), "Cleaning student room"));

    // Create some yearly appointments
    calendar.addAppointment(new YearlyAppointment(LocalDateTime.of(2021, 3, 5, 9, 00), "Birthday mother"));
    calendar.addAppointment(new YearlyAppointment(LocalDateTime.of(2021, 1, 1, 0, 00), "New year"));

    // Use this space below to test your application!
    ArrayList<Appointment> result = calendar.getAppointments(2021);
    
    //...
}