Solved by verified expert:JAVA, Event Calendar Make sure to run Checkstyle on your program, please see the files. and do the same instruction.Thanks.
2018spring_cs117_hw04_assignment__1_.pdf
2017spring_cs117_homework04.zip
Unformatted Attachment Preview
Name
CS117 – Homework 04 – Page 1
Homework 04: Event Calendar
Assigned: Monday, February 26, 2018
Due: Friday, March 12, 2018 at 6:00am
1
Background: Working With Dates
Keeping track of the current day of the year is a surprisingly complicated task, because of leap
years and time zones and other details that we might not think of. Fortunately, Java comes with
professionally-designed classes for doing this work. The newest version of Java (called either Java
8 or Java 1.8 at different times) includes a brand new class that is especially easy to use, named
LocalDate. If you are not currently using Java 8 / 1.8, you will need to upgrade for this assignment.
You can read the documentation for the LocalTime class at https://docs.oracle.com/javase/
8/docs/api/java/time/LocalDate.html, but I am going to summarize just the most important
features that you will need for this assignment.
This class needs to be imported, just like ArrayList, HashSet, Iterator, and HashMap. But
while all of those classes were in the package java.util, LocalDate is in the package java.time.
Strangely, LocalDate does not have any constructors, and so we cannot create LocalDate
objects in the usual way. But instead, the class has a static method with this signature:
1
public static LocalDate of ( int year , int month , int dayOfMonth )
So if I wanted to make an object to store date on which this homework was assigned, I would
do it like this:
1
LocalDate startDate = LocalDate . of (2018 , 2 , 26) ;
Here are the signatures of some of the instance methods the LocalDate class has:
1
2
3
4
5
6
public
public
public
public
public
public
boolean equals ( Object other )
int getDayOfMonth ()
DayOfWeek getDayOfWeek ()
int getMonthValue ()
int getYear ()
String toString ()
The third requires a bit of further explanation. It returns a member of another class, DayOfWeek
, which happens to be an enumeration similar to the one I used as an example in class. This class
also needs to be imported from java.time. It has constants named MONDAY, TUESDAY, etc. It also
has a static method with the following signature, that returns MONDAY for 1, TUESDAY for 2, etc:
1
public static DayOfWeek of ( int dayOfWeek )
2
Overview
We are going to write a program that helps you keep track of your appointments and events.
Name
3
CS117 – Homework 04 – Page 2
Assignment: Event Class
Create an abstract class named Event. It should have a field for the name of the event, and
constructors / methods with the following signatures:
1
2
3
public Event ( String theName )
public String getName ()
public abstract boolean isOnDay ( LocalDate when )
4
Assignment: OneTimeEvent Class
Create a class named OneTimeEvent for an event that occurs on only a single day. (Example: on
February 28, 2017 Dr. Hogg has a dentist appointment.) It should be a subclass of Event. It
should have a field to store that day, and should have constructors / methods with the following
signatures:
1
2
public OneTimeEvent ( String theName , LocalDate theDate )
public boolean isOnDay ( LocalDate when )
5
Assignment: MonthlyEvent Class
Create a class named MonthlyEvent for an event that repeats on the same day of every month.
(Example: on the 7th day of every month Dr. Hogg’s recycling is collected.) It should be a subclass
of Event. It should have a field to store the day of the month, and should have constructors /
methods with the following signatures:
1
2
public MonthlyEvent ( String theName , int theDayOfMonth )
public boolean isOnDay ( LocalDate when )
6
Assignment: WeeklyEvent Class
Create a class named WeeklyEvent for an event that repeats on the same day of every week.
(Example: every Tuesday Dr. Hogg has CS117 lab.) It should be a subclass of Event. It should
have a field to store the day of the week, and should have constructors / methods with the following
signatures:
1
2
public WeeklyEvent ( String theDay , DayOfWeek theDayOfWeek )
public boolean isOnDay ( LocalDate when )
Name
7
CS117 – Homework 04 – Page 3
Assignment: Main Class
Add a main method to the Main class. The main method should have a local variable to store an
ArrayList of Event objects.
The main method should use a loop to repeatedly offer three options to the user: add (a new
event), view (the events for a day), and quit (the program), doing so until they choose to quit.
If the user wants to add a new event, it should ask which type, collect the necessary information,
create a new instance, and add it to the ArrayList. (You should use the getNewEventName method
that I provided.)
If the user wants to view the events for a day, it should ask the year, month number, and day
number, then print the names of the events occurring that day.
See below for an example input / output session.
8
Finishing
Make sure to run Checkstyle on your program, because any complaints that it has will lead to
deductions in your grade.
Also be sure to thoroughly test your program and make sure that it works correctly. I have
included a sample of my program running below. Yours does not need to look exactly the same,
but it should provide the same kind of information and work the same way.
When you are sure that your program is perfect, create an archive file of your CS117-HW04
folder and upload it to Moodle.
9
Sample Session
add (a new event)
view (the events for a day)
quit (the program)
Your choice: add
Event name: Dentist appointment
Type: (once, monthly, or weekly): once
Year: 2017
Month number: 2
Day: 28
Creating Dentist appointment on 2017-02-28.
add (a new event)
view (the events for a day)
quit (the program)
Your choice: add
Event name: CS117 Lab
Type: (once, monthly, or weekly): weekly
Weekday number (M = 1, T = 2, …): 2
Name
Creating CS117 Lab on every TUESDAY.
add (a new event)
view (the events for a day)
quit (the program)
Your choice: add
Event name: Recycling Pickup
Type: (once, monthly, or weekly): monthly
Day of month: 7
Creating Recycling Pickup on day 7 of each month.
add (a new event)
view (the events for a day)
quit (the program)
Your choice: view
Year: 2017
Month number: 2
Day: 28
Your schedule for 2017-02-28 includes:
Dentist appointment
CS117 Lab
add (a new event)
view (the events for a day)
quit (the program)
Your choice: view
Year: 2017
Month number: 3
Day: 7
Your schedule for 2017-03-07 includes:
CS117 Lab
Recycling Pickup
add (a new event)
view (the events for a day)
quit (the program)
Your choice: view
Year: 2017
Month number: 3
Day: 6
Your schedule for 2017-03-06 includes:
nothing at all!
CS117 – Homework 04 – Page 4
Name
add (a new event)
view (the events for a day)
quit (the program)
Your choice: quit
Have a good day!
CS117 – Homework 04 – Page 5
…
Purchase answer to see full
attachment