Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for a JAVA Course please see below thank you in advance! ----------------------------------------------------- Java 8 introduced new APIs for Date and Time to address

This is for a JAVA Course please see below thank you in advance!

-----------------------------------------------------

  • Java 8 introduced new APIs for Date and Time to address the shortcomings of the older java.util.Date and java.util.Calendar. You have to use these new features of Java 8 to manipulate time information in your program. Study the API of classes in java.time package to learn how to manipulate day, week and month of calendar. Here is an example code to learn how to advance a calendar by month, to print a date in a specified format, and to figure out the day of the week for the 1st day of the given month.
 import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Scanner; public class DateTimeExample { public static void main(String [] args) { LocalDate cal = LocalDate.now(); // capture today Scanner sc = new Scanner(System.in); System.out.print("Today: "); printCalendar(cal); while (sc.hasNextLine()) { String input = sc.nextLine(); if (input.equals("p")) { cal = cal.minusMonths(1); // LocalDateTime is immutable printCalendar(cal); } else if (input.equals("n")) { cal = cal.plusMonths(1); // LocalDateTime is immutable printCalendar(cal); } } System.out.println("Bye!"); } public static void printCalendar(LocalDate c) { System.out.print(c.getDayOfWeek()); System.out.print(" "); System.out.print(c.getDayOfMonth()); System.out.print(" "); System.out.println(c.getMonth()); // To print a calendar in a specified format. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E, MMM d yyyy"); System.out.println(" " + formatter.format(c)); // To figure out the day of week of the 1st day of the given month LocalDate x = LocalDate.of(c.getYear(), c.getMonth(), 1); System.out.println(x.getDayOfWeek() + " is the day of " + c.getMonth() + " 1."); // enum value as it is System.out.println(x.getDayOfWeek().getValue() + " is an integer value corresponding " + " to " + x.getDayOfWeek()); // int value corresponding to the enum value } } 

  • In your implementation, ignore cases to recognize a user request and make sure to follow the given example format to enter data.
    • MyCalendarTester class with a main method
    • MyCalendar class that defines an underlying data structure to hold events.

In this assignment, you will design and implement a calendar similar to the one you can find on your phone. The calendar is going to be implemented as a console application.

The initial screen shows the current month looking like this. It also highlights today's date using a pair of brackets. (It is not straightforward to highlight on the console. It is fine to use a pair of brackets for this purpose.)

 March 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [20] 21 22 23 <-- It is ok if this line is sticking out. 24 25 26 27 28 29 30 31 

When the program starts, it loads events from events.txt and populates the calendar with them. The events.txt is a text file of an event you need to prepare ahead of the program execution.

There are two different types of events the program manages: regular and one-time.

  • A regular event is one that is scheduled every week on the same day or days, such as a lecture that meets every Monday and Wednesday.
  • A one-time event is scheduled on a particular date, such as 10/15/19, and doesn't repeat.

In the event.txt file, each event takes up two lines.

  • Regular event The first line contains the name of the event which may contain spaces. The second line consists of a sequence of day abbreviations (SMTWRFA, upper or lower case) followed by a starting date and an ending date of the regular event.
  • One time event The first line contains the name of the event which may contain spaces. The second line consists of a date in the format mm/dd/yy, e.g.3/22/19. There cannot be any spaces within a date description. the date description is followed by a starting time and an ending time. For the starting and ending times, only military 24-hour time will be used for simplicity. For example, 18:15 instead of 6:15 pm The minutes cannot be left off in which case zeros should be specified for the minutes, e.g. 14:00.

Here is a sample events.txt:

CS151 Lecture TR 10:30 11:45 1/24/19 5/9/19 CS157C Lecture MW 11:45 13:15 1/28/19 5/13/19 Interview at Apple 9/28/19 9:30 11:30 Dentist appt 10/3/19 16:15 17:00 Course Committee Meeting F 18:30 20:30 1/25/19 5/13/19 

After loading the events, the program prompts "Loading is done!". The program now displays a main menu with following options: View by, Create, Go to, Event list, Delete, and Quit. After the function of an option is done, the main menu is displayed again for the user to choose the next option.

Select one of the following options: [V]iew by [C]reate, [G]o to [E]vent list [D]elete [Q]uit 

The user may enter one of the letters highlighted with a pair of the bracket to choose an option. For example,

V 

will choose the View by option.

  • [V]iew by The user can choose a Day or a Month view. If a Day view is chosen, the program prints today's date. If there is an event(s) scheduled on that day, display them in the order of start time of the event. With a Month view, it displays the current month and highlights day(s) with a pair of brackets {} if any event scheduled on that day. After a view is displayed, the calendar gives the user three options: P, N, and G, where P, N, and M stand for Previous, Next and Go back to the main menu, respectively. The previous and next options allow the user to navigate the current view back and forth. If the day view was selected, the view goes back (P) and forth (N) by day. If the month view was chosen, the view goes back (P) and forth (N) by month. Here are sample runs:
    [D]ay view or [M]view ? 
    If the user selects D, then today's date is displayed along with scheduled events.
    Thu, March 19, 2019 CS151 Lecture : 10:30 - 11:45 [P]revious or [N]ext or [G]o back to main menu ? 
    If the user selects M, then
     March 2019 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [19] 20 21 22 23 24 25 26 27 28 29 30 31 [P]revious or [N]ext or [G]o back to main menu ? 
    Note: The following example code segment shows how to print the given date in a specified format.
    LocalDate c = .... DateTimeFormatter formatter = DateTimeFormatter.ofPattern("E, MMM d yyyy"); System.out.println(" " + formatter.format(c));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions