Question
1 Objective In this assignment you will be provided with a partially written superclass. You will complete it, then also write several subclasses. You will
1 Objective In this assignment you will be provided with a partially written superclass. You will complete it, then also write several subclasses. You will practice overriding methods, especially the ones that every object class should override.
2 Setup Create a new Java Project (Lab03). Download the Lab03Files.zip file, unzip it, and place the classes it contains into your projects source folder. (You should be able to find it from the handout link just beside the one where this writeup was found.) You may need to tell Eclipse to refresh the project before it sees the files that you added. You should have the following classes: Event An abstract class that represents a thing you want to be reminded about. This class is only partially written. In particular, the bodies of all constructors and methods are empty, and some methods are missing. CalendarProgram A program that will allow you to use the Event class and its subclasses. This class will not compile until you are finished writing the others. You do not need to make any changes to this class, but can read through it if you wish.
3 Project Description We are building a calendar to help you keep track of your events, like Google Calendar or Windows Calendar. It will not have a very fancy interface, but one could be bulit that uses your classes as they are. We will support several kinds of events: One-time events These happen just once ever. For example, you might have a dentist appointment 10:00-10:30 on October 3, 2020. Repeating monthly events These happen on the same day each month. For example, you might have a meeting with your housemates 8:00-8:30 on the first day of every month to pay your utility bills. Repeating weekly events These happen on the same day each week. For example, you might play board games with your friends every Friday night 18:00-22:00. Repeating events have a first day and then a number of times that they repeat (or repeat infinitely). For simplicity, we are not supporting events that repeat annually or on the 1st and 3rd Monday of each month, or in any other complicated way. CSCI162 - Lab 03 2
4 Background Information In order to build a calendar application we are going to need to deal with dates and times. This can be much more complicated than it sounds you need to think about leap years and time zones and all sorts of other weird cases. Fortunately, the Java libraries (starting with version 8) include two pre-built classes LocalDate and LocalTime to represent dates and times respectively. These classes must be imported from the java.time package if you wish to use them. These classes have lots of methods, but here is a short list of the ones from the LocalDate class that I expect that you will find useful: int getDayOfMonth() returns which day of the month (i.e., the 3rd) this date represents. DayOfWeek getDayOfWeek() returns which day of the week (i.e., Monday) this date represents. boolean isAfter(LocalDate other) tells you whether or not this date is after the other date. boolean isBefore(LocalDate other) tells you whether or not this date is before the other date. LocalDate plusMonths(long monthsToAdd) returns a new date that number of months in the future of the original date. LocalDate plusWeeks(long weeksToAdd) returns a new date that number of weeks in the future of the original date. And here is a short list from LocalTime: boolean isAfter(LocalTime other) tells you whether or not this time is after the other time. boolean isBefore(LocalTime other) tells you whether or not this time is before the other time. Being well-designed classes, they of course also have reasonable overrides of toString, equals, and hashCode. You can read their full documentation at https://docs.oracle.com/en/java/ javase/14/docs/api/java.base/java/time/LocalDate.html and https://docs.oracle.com/ en/java/javase/14/docs/api/java.base/java/time/LocalTime.html if you wish.
5 Instructions / Specifications
5.1 Finishing The Event Class Add yourself as an author in the classs Javadoc comment. Fill in the bodies of all constructors and methods, reading their documentation carefully to know what they should do. Override the toString method to return a string like "Dentist Appointment (10:00-10:30)". Override the equals method to indicate that an Event is equivalent to the other object if it is the same class and has the same name, start time, and end time. CSCI162 - Lab 03 3 Override the hashCode method in any way that follows the general contract for hashCode methods: two equivalent objects must get the same number, two non-equivalent objects should be very unlikely to get the same number.
5.2 Writing The OneTimeEvent Class Create a new class named OneTimeEvent, which should be a subclass of Event. Give it one field: a LocalDate named date. This will represent the day on which the event occurs. Give it a constructor with four parameters for the event name, date, start time, and end time. Override the isOnDay method. The event is on a day if the dates match exactly. Override the toString method to return a string like "Dentist Appointment (10:00-10:30) on 2020-10-03". Override the equals and hashCode methods in appropriate ways.
5.3 Writing The RepeatingEvent Class Create a new abstract class named RepeatingEvent, which should be a subclass of Event. Give it two fields. The first is a LocalDate named firstOccurrence, which stores the date of the first time the event occurs. The second is an int named repetitions, which stores the number of times the event will repeat after the first time. This may be 0 to indicate that it repeats an infinite number of times. It may not be negative. Give it a constructor with five parameters for the event name, date of first occurrence, number of repetitions, start time, and end time. Give it accessor methods for the date of first occurrence and number of repetitions. Do not override the isOnDay method, as we do not have enough information to answer that question. Override the toString method to return either a string like "Board Games (18:00-22:00) repeating for all " or "Board Games (18:00-22:00) repeating for 12 ", depending on whether or not it has a fixed number of repetitions. Override the equals and hashCode methods in appropriate ways.
5.4 Writing The MonthlyEvent Class Create a new class named MonthlyEvent, which should be a subclass of RepeatingEvent. Do not give it any fields. CSCI162 - Lab 03 4 Give it a constructor with five parameters for the event name, date of first occurrence, number of repetitions, start time, and end time. Override the isOnDay method. For the event to be on that day, it will need to be the same day of the month as the date of first occurrence, not before the first occurrence, and (if there is a limited number of repetitions) not after the last repetition. We will count a repetition as occurring each month even if the event does not actually happen (i.e., something that would be on the 30th of February). Override the toString method to return either a string like "House Meeting (8:00-8:30) repeating for all months starting on 2020-01-01" or "House Meeting (8:00-8:30) repeating for 12 months starting on 2020-01-01", depending on whether or not it has a fixed number of repetitions. Do not override the equals or hashCode methods, since the superclass versions should already be doing the correct thing.
5.5 Writing The WeeklyEvent Class Create a new class named WeeklyEvent, which should be a subclass of RepeatingEvent. Do not give it any fields. Give it a constructor with five parameters for the event name, date of first occurrence, number of repetitions, start time, and end time. Override the isOnDay method. For the event to be on that day, it will need to be on the same day of the week as the date of first occurrence, not before the first occurrence, and (if there is a limited number of repetitions) not after the last repetition. Override the toString method to return either a string like "Board Games (18:00-22:00) repeating for all weeks starting on 2020-09-11" or "Board Games (18:00-22:00) repeating for 8 weeks starting on 2020-09-11", depending on whether or not it has a fixed number of repetitions. Do not overide the equals or hashCode methods, since the superclass version should already be doing the correct thing.
5.6 Testing & Submitting Your Work Run the provided CalendarProgram class, which should now compile. You should be able to add events of any type, view your schedule for a day, and see events described in meaningful ways. Because you wrote multiple files, you will need to zip up the src directory in your project folder, and upload that zip file to AutoLab. The way to do this will be different depending on your operating system, but you should be able to find a way to zip or compress or CSCI162 - Lab 03 5 send to compressed folder if you right-click on the directory in your operating systems file browser. If you cannot figure this out, ask for help. Remember to re-zip the directory every time you submit, or you will still be submitting the old version.
I posted the partial code talked about in my next question.
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