Question: Java, please. There is no sample input and output. Define a class to model a daily calendar. The calendar keeps track of the appointment for
Java, please. There is no sample input and output.


Define a class to model a daily calendar. The calendar keeps track of the appointment for each hour of the day. For the data, use an array of 24 Strings, each representing the appointment for that hour (or "Open" if there is no appointment). Map the hours to the array this way... Array index --- Hour 0 --- 12 AM (Midnight) 1 1 AM 2 --- 2 AM 3 --- 3 AM 11 --- 11 AM 12 --- 12 PM (Noon) 13 - 1 PM 14 --- 2 PM 15 --- 3 PM 23 --- 11 PM For example, array index 3 will hold the appointment for 3 AM. Provide the following functionality: a constructor (start with all 24 hours "Open") a toString method (to include all 24 hours) an accessor to return the appointment at a given hour a mutator to set the appointment at a given hour to a given String a method to test if a given hour is still available (return true if "Open", and false otherwise) For "a given hour", pass an integer (1-12) and a character code ('A' for AM, and 'P' for PM) To reduce and improve the code, write a private helper method to return the array index of a given hour. Also define a class to test the calendar containing a main program that does the following: (a) create an empty calendar. (b) set 1 AM to 8 AM to "Sleep" (c) choose a random hour from 1 PM to 12 PM and set that hour to "Eat" (d) choose another random hour from 1 PM to 12 PM and set that hour to "Play" (d) test if 11 PM is available to watch "Resident Alien". If it is not available, then display the appointment for that hour, otherwise, set that hour to "Resident Alien" Notice that there is no input from the user. This does not have to be compiled and tested. For Random Numbers... To generate random numbers, use the following: import java.util.*; Then create a random number generator. Make it a data member of the main program class so that it can be shared by all the methods. private static Random generator = new Random(); To generate one random integer from 1 up to 12: int nextInt; nextInt = generator.nextInt(12)+1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
