You to write a class named weaklycalendar this class must


Programming Assignment

You to write a class named WeaklyCalendar. This class must be in a package named pa4.

Note that the description of a programming assignment is not a linear narrative and often requires multiple readings before things start to click. You are encouraged to consult instructors/Teaching Assistants for any questions/clari?cations regarding programming assignments. 1 Calendar You will be writing a program to implement a baby version of Google calendar/iCal to keep track of appointments. A Calendar program stores all appointments, and you can add an appointment to the calendar, or delete an existing appointment. For our purposes, we work with weekly calendar

(not monthly/yearly calendars).

An appointment has two ?elds: Day of the appointment, time of the appointment. Suppose you have an appointment on Monday at 5PM. This information can be represented as string of the form "Monday@5PM". Similarly an appointment on Tuesday at 8AM can be represented with the string "Tuesday@8AM".

For the sake of this program we make some simplifying assumptions. Every appointment starts at the top of the hour, and lasts for at most one hour. For example, we do not allow appointments that start at 5:30PM, nor we allow appointments that start at 6AM and end at 8AM.

All the data about appointments is initially stored in a text ?le named myCalendar.txt. This ?le consists of words and each word describes an appointment. Here is a sample contents of the ?le Monday@5PM, Tuesday@2PM andFriday@6PM.

Note that each appointment is described by a single word.

Your task is to write a program that reads the appointment data from the ?le named myCalendar.txt.

Once it reads the data from this ?le, the program interacts with the user. The user can add an appointment, remove and appointment or print the calendar on the screen etc. 2 Your Task Your task is to a write program named WeeklyCalendar that keeps track of all appointments. For this you will be writing several methods. Your program must have the following method. readFromFile. This method reads appointments from a ?le named myCalendar.txt. This ?le is stored in the projects folder. The format of the ?le is as described above. This method returns an 1 array list of Strings. Each word of the ?le myCalendar.txt will be an element of the array list. For example if the contents of the ?le are as described above, then this method returns an array list (of Strings) of size 3. The string at index 0 is "Monday@5PM", String at index 1 is "Tuesday@2PM", and String at index 2 is "Friday@6PM". From now we will refer to this list as appointment list.

hasAppointmentAt. This method takes three parameters with following names and types.

• appointmentList. This is an array list of strings that represents all appointments.

• specifiedDay. A string representing weekday.

• specifiedTime A string representing time. This of form "hhAM" or "hhPM". For example, "9AM" or "10PM".

This method searches appointmentList for an appointment on specifiedDay at specifiedTime.

If found, the method returns true. Otherwise, the method returns false.

addAppointment. This method takes three parameters with following names and types.

• appointmentList. This is an array list of strings representing all appointments.

• specifiedDay. A string representing weekday.

• specifiedTime A string representing time. This of form "hhAM" or "hhPM".

This method ?rst searches whether there already exists an appointment at specifiedTime on specifiedDay. If so, then this method returns false. Otherwise, this method adds appointment to the appointmentList and returns true removeAppointment. This method takes three parameters with following names and types.

• appointmentList. This is an array list of strings representing all appointments.

• specifiedDay. A string representing weekday.

• specifiedTime A string representing time. This of form "hhAM" or "hhPM".

This method ?rst searches appointmentList whether there is appointment at specifiedTime on specifiedDay. If so, then this method removes that appointment and returns true. Otherwise, this method returns false.

appointmentsOnDay. This method takes two parameters with following names and types.

• appointmentList. This is an array list of strings representing all appointments.

• specifiedDay. A string representing a week day.

This method returns an array list (of Strings) consisting of all appointments on specifiedDay.

printAppointmentCalendar. This method takes a variable named appointmentList (which is an array list of Strings) representing all appointments, and prints all appointments of the week on the screen. Each line of the output starts with weekday followed by appointments on that day. Since there are seven weekdays, the output has 7 lines. An example output is as follows:

2 Monday: 2PM 8AM 3PM

Tuesday:

Wednesday: 11AM 12PM

Thursday: 2PM 8AM 11AM

Friday:

Saturday: 9AM 10AM 12PM 5PM 8PM

Sunday:

main. This is the main method. The main method ?rst reads the appointments from a ?le named myCalendar.txt and stores them in an array list (by calling the method readFromFile). Then it repeatedly prompts the user to enter one of "addAppointment", "removeAppointment", "printDay", "printAll" or "quit" until user enters "quit". For each of the responses that user enters, the program behaves as follows:

addAppointment. Prompts the user to enter day and time of appointment to be added(day must be a weekday, and time is of the form "hhAM", or "hhPM"). If there is already another appointment at that time and day then display a message saying so. If there is no appointment at that time and day, then adds the appointment.

removeAppointment. Prompts the user to enter day and time of appointment to be deleted(day must be a weekday, and time is of the form "hhAM", or "hhPM"). If there is no appointment at that time and day, then displays a message saying so. If there is an appointment at that time and day then deletes the appointment.

printDay. Prompts the user to enter a weekday and prints all appointments on that day.

printAll. Prints all appointments for the entire week.

quit. Program terminates.

Below is a sample run of the program. Boldface text indicates user input.

Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

addAppointment

Enter day and time

Friday 8AM

There is another appointment at that time, can not add.

Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

addAppointment

Enter day and time

Tuesday, 1PM

Added Appointment 3 Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

removeAppointment

Enter day and time

Thursday 2PM

Removed appointment

Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

removeAppointment

Enter day and time

Friday 2PM

No appointment at that time, can not remove.

Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

printDay

Enter weekday

Thursday

Thursday Appointemnts: 2PM 8AM 10PM

Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

printAll

Weekly Calendar:

Monday: 8AM

Tuesday: 10AM 9AM 12PM

Wednesday: 2PM

Thursday:

Friday: 8AM

Saturday: 9AM 11AM 5PM

Sunday: 10AM

Please enter one of the following:

addAppointment, removeAppointment, printDay, printAll, quit

quit

Quitting. 3 User Input You may assume that the user always enters a valid input. For example, when prompted for weekday, the user enters one of the weekdays. When prompted for time user enters time in the format "hhAM" or "hhPM". For example, the user will not enter an input of the form 930AM.

4 4 String methods You may ?nd the following string methods useful: indexOf, substring, length and String concatenation. 5 Coding Conventions You must follow good coding conventions. Variable names must be meaningful, variable names (and method names) must start with lower case letters, code must be properly indented. Your code must have appropriate comments. Failure to follow good coding conventions will cause you to lose points (even if your solution is correct). 6 Suggestions Do not attempt to write code for all the methods at once. Write one method at a time, test that the method works correctly then proceed to the next method. 7 Speci?cations You must follow the speci?cations exactly. Your program must be named WeeklyCalendar and should be in a package named pa4. Please note that Java is case-sensitive. The input-output behavior of your program must be exactly as described. Failure to follow the speci?cations (even if your solution is correct) will cause you to lose points. Submit WeeklyCalendar.java via blackboard.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: You to write a class named weaklycalendar this class must
Reference No:- TGS01706927

Now Priced at $40 (50% Discount)

Recommended (95%)

Rated (4.7/5)