Question: Part B: Date book(java) A classic computer application is the electronic date book: a list of daily events stored in a calendar. Write a Java
Part B: Date book(java)
A classic computer application is the electronic date book: a list of daily events stored in a calendar. Write a Java program that can be used as a simple date book. The date book will use a separate array for each month of the year, with one array entry for each day in the month (0 = first day of the month, 1 = second day of the month, etc.). The date book is "simple" because at most one event will be allowed on each day.
Your program should include an Event class that will be instantiated for each event in the date book. The Event class consists of three instance variables: the starting time of the event (a String), the name of the event (a String), and the priority of the event (an integer value in the range 1-3, with 3 being the highest priority). Make all your instance variables private and write appropriate instance methods for processing them, including a constructor, toString(), and any others needed by your program.
Each month in the date book will be stored as an array of Events. Days with an event will point to the appropriate Event object, and days without will contain null.
Your program will produce three types of output (three views) for each month:
A calendar view, listing the days of the week (Sunday to Saturday) horizontally across the top, and the days of the month underneath. Next to each day where there is a scheduled event, print an asterisk "*". Like in a real calendar, the first day of the month can be any of the weekdays.
A list of events, showing the day of the month and the details of the event (using toString). These can be displayed in the order that they occur during the month. Do not display lines of output for days without events.
A list of the highest-priority events (those with priority 3). List only the names of the events, not the starting time or priority.
For example:
Sun Mon Tue Wed Thu Fri Sat 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 Events: 2: 4:00 PM: Event #8 (priority 3) 11: 2:00 PM: Event #10 (priority 1) 12: 5:00 PM: Event #7 (priority 3) 14: 10:00 PM: Event #2 (priority 1) 15: 6:00 PM: Event #6 (priority 3) 16: 7:00 PM: Event #5 (priority 2) 19: 3:00 PM: Event #9 (priority 2) 25: 9:00 PM: Event #3 (priority 1) 26: 11:00 PM: Event #1 (priority 3) 28: 8:00 PM: Event #4 (priority 1) High-priority events: 2: Event #8 12: Event #7 15: Event #6 26: Event #1
Write a separate static method to generate each view. Test your program as follows:
Create two arrays of Events, september and october; the first has 30 entries, the second 31.
Place 10 events at random locations in each array. Write one method to do this, and call it twice (i.e. the two arrays will contain the same ten events on different days). Make up reasonable values for the names and starting times of the events: make them all recognizably different and meaningful (not just "Event 1", "Event 2", etc.). The method should choose a random number between 1-3 for event priority.
Display the complete output (all three views) for September. Choose the first day of the month randomly (pick a random number 0-6 where 0 is Sunday).
Display the complete output (all three views) for October. The first day of the month will be (the first day of September + 30) mod 7: that is, it will continue after September's last day.
Make sure to title both parts of your output (September and October) clearly. Remember from COMP 1010 that you can choose a random number between 1 and n using (int)(Math.random() * n) + 1.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
