Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment, you will design and implement a calendar similar to one you

ID: 3906186 • Letter: I

Question

In this assignment, you will design and implement a calendar similar to one you can find in 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, for example, using a pair of brackets. (It is not straightforward to highlight on console. It is fine to use a pair of brackets for this purpose.)

The initial screen comes with 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.

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

will choose the View by option.

[L]oad
The system loads events.txt to populate the calendar. If there is no such file because it is the first run, the load function prompts a message to the user indicating this is the first run. You may use Java serialization this function.

[V]iew by
User can choose a Day or a Month view. If a Day view is chosen, the calendar displays the current 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 M, where P, N, and M stand for previous, next, and main menu, respectively. The previous and next options allow the user to navigate the calendar back and forth by day if the calendar is currently in a day view or by month if it is in a month view. If the user selects M, navigation is done, and the user gets to access the main menu again.

If the user selects D, then

If the user selects M, then

[C]reate
This option allows the user to schedule an event. The calendar asks the user to enter the title, date, starting time, and ending time of an event. For simplicity, we consider one day event only. Your program should check if if a new event is conflict with existing events. Please stick to the following format to enter data:

Title: a string (doesn't have to be one word)

date: MM/DD/YYYY

Starting time and ending time: 24 hour clock such as 06:00 for 6 AM and 15:30 for 3:30 PM. The user may not enter ending time if an ending time doesn't make sense for the event (e.g. leaving for Korea event may have a starting time but no ending time.)

[G]o to
With this option, the user is asked to enter a date in the form of MM/DD/YYYY and then the calendar displays the Day view of the requested date including any event scheduled on that day in the order of starting time.

[E]vent list
The user can browse scheduled events. The calendar displays all the events scheduled in the calendar in the order of starting date and starting time. An example presentation of events is as follows:

[D]elete
User can delete an event from the Calendar. User will be first asked to enter a specific date, e.g. 06/03/2018. And then will be asked to choose from two options: [S]elected and [A]ll.

[S]elected: selected event will be deleted from the specified date.

[A]ll: all the events scheduled on the specified date will be deleted.

[Q]uit saves all the events scheduled in a text file called "events.txt" in the order of starting date and starting time. (If you know how to use Java serialization, use it. Otherwise, get the data using accessors and write them to the file.

The main menu will be displayed after each option is done. It is crucial to have a user friendly interface for the user to enter input. For example, if the calendar needs a date from the user, suggest a specific format of the date for the user to use. Our class grader will be the user to operate your calendar, and you don't want to frustrate the user with a confusing interface.

Explanation / Answer

Below is your code.

CalendarManager.java

public class CalendarManager {

private HashMap<GregorianCalendar, ArrayList<Event>> Events;

private int[][] Calendar; // empty Array

private ArrayList<Day> EventDays = new ArrayList<Day>();

private int j = 0;

private Day[][] EventCalendar;

private String[][] EventStored;

static int maxWeekOfMonth, maxDayOfWeek, fdayOfWeek, AllDaysOfMonth, fDayOfMonth, realMonth, realYear, currentMonth,

currentYear, indexOfFirst, currentDay, weekDayInfo;

public CalendarManager() {

Events = new HashMap<GregorianCalendar, ArrayList<Event>>();

GregorianCalendar cal = new GregorianCalendar();

realMonth = cal.get(GregorianCalendar.MONTH);

realYear = cal.get(GregorianCalendar.YEAR);

fillCalendar(realMonth, realYear);

Day x = new Day(realMonth, 0, realYear);

fillEventCalendar(x);

}

/**

* Method that fills the calendar based on month and year

*

* @param month

* The month to add

* @param year

* The year to add

*/

public void fillCalendar(int month, int year) {

GregorianCalendar cal = new GregorianCalendar(year, month, 1);

maxWeekOfMonth = cal.getActualMaximum(GregorianCalendar.WEEK_OF_MONTH); // max

// weeks

// in

// month

// 4

// or

// 5

maxDayOfWeek = cal.getActualMaximum(GregorianCalendar.DAY_OF_WEEK); // maximum

// days

// in

// a

// week

// or

// 7

fdayOfWeek = cal.get(GregorianCalendar.DAY_OF_WEEK); // returns weekday

// ex. Monday

AllDaysOfMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); // returns

// maximum

// amount

// of

// days

// in

// the

// month

fDayOfMonth = cal.get(GregorianCalendar.DAY_OF_MONTH); // returns the

// firstMonth

realMonth = cal.get(GregorianCalendar.MONTH); // Returns current Month

// to Date

realYear = cal.get(GregorianCalendar.YEAR); // Returns current Year to

// Date

indexOfFirst = cal.get(GregorianCalendar.DAY_OF_WEEK) - 1; // Returns

// what

// WeekDay

// Index to

// start at

currentMonth = realMonth; // setting month

currentYear = realYear; // setting year

currentDay = fDayOfMonth;

Calendar = new int[maxWeekOfMonth][maxDayOfWeek];

fdayOfWeek--;

for (int m = 0; m < Calendar.length; m++) {

while (fDayOfMonth <= AllDaysOfMonth && fdayOfWeek < maxDayOfWeek) {

Calendar[j][indexOfFirst] = fDayOfMonth;

fDayOfMonth++;

fdayOfWeek++;

indexOfFirst++;

}

j++;

indexOfFirst = 0;

fdayOfWeek = 0;

}

fDayOfMonth = 0;

fdayOfWeek = 0;

j = 0;

}

/**

* Method that fills calendar with days

*

* @param d

* The Day object to add

*/

public void fillEventCalendar(Day d) {

GregorianCalendar cal = new GregorianCalendar(d.getYear(), d.getMonth(), 1);

maxWeekOfMonth = cal.getActualMaximum(GregorianCalendar.WEEK_OF_MONTH); // max

// weeks

// in

// month

// 4

// or

// 5

maxDayOfWeek = cal.getActualMaximum(GregorianCalendar.DAY_OF_WEEK); // maximum

// days

// in

// a

// week

// or

// 7

fdayOfWeek = cal.get(GregorianCalendar.DAY_OF_WEEK); // returns weekday

// ex. Monday

AllDaysOfMonth = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); // returns

// maximum

// amount

// of

// days

// in

// the

// month

fDayOfMonth = cal.get(GregorianCalendar.DAY_OF_MONTH); // returns the

// firstMonth

realMonth = cal.get(GregorianCalendar.MONTH); // Returns current Month

// to Date

realYear = cal.get(GregorianCalendar.YEAR); // Returns current Year to

// Date

indexOfFirst = cal.get(GregorianCalendar.DAY_OF_WEEK) - 1; // Returns

// what

// WeekDay

// Index to

// start at

currentMonth = realMonth; // setting month

currentYear = realYear; // setting year

currentDay = fDayOfMonth;

EventCalendar = new Day[maxWeekOfMonth][maxDayOfWeek];

EventStored = new String[maxWeekOfMonth][maxDayOfWeek];

fdayOfWeek--;

for (int m = 0; m < Calendar.length; m++) {

while (fDayOfMonth <= AllDaysOfMonth && fdayOfWeek < maxDayOfWeek) {

Day newDay = new Day(d.getMonth(), fDayOfMonth, d.getYear());

EventCalendar[j][indexOfFirst] = newDay;

fDayOfMonth++;

fdayOfWeek++;

indexOfFirst++;

}

j++;

indexOfFirst = 0;

fdayOfWeek = 0;

}

fDayOfMonth = 0;

fdayOfWeek = 0;

j = 0;

}

/**

* Method that displays weekday headers

*/

public void displayWeekdays() {

String[] headers = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" }; // All

// headers

for (int i = 0; i < 7; i++) {

System.out.print(headers[i] + " ");

}

}

/**

* Method that displays month headers based on month

*

* @param months

* The month to display

* @return

*/

public String monthDisplay(int months) {

String[] allMonths = { "January", "February", "March", "April", "May", "June", "July", "August", "September",

"October", "November", "December" };

return allMonths[months];

}

/**

* Method that prints the menu calendar to the user

*/

public void printCalendar() {

GregorianCalendar cal = new GregorianCalendar();

System.out.println(monthDisplay(realMonth) + " " + realYear);

displayWeekdays();

System.out.print(" ");

int todaysDate = cal.get(GregorianCalendar.DAY_OF_MONTH);

for (int row = 0; row < Calendar.length; row++) {

for (int column = 0; column < Calendar[0].length; column++) {

if (Calendar[row][column] == todaysDate && realMonth == currentMonth) {

Calendar[row][column] = todaysDate;

System.out.print("[" + Calendar[row][column] + "]" + "");

}

if (Calendar[row][column] == todaysDate && realMonth != currentMonth) {

Calendar[row][column] = todaysDate;

System.out.print(Calendar[row][column] + " ");

} else if (Calendar[row][column] != todaysDate && Calendar[row][column] == 0) {

System.out.print(" ");

} else if (Calendar[row][column] != todaysDate && Calendar[row][column] < 10) {

System.out.print(" " + Calendar[row][column] + " ");

} else if (todaysDate != Calendar[row][column]) {

System.out.print(Calendar[row][column] + " ");

}

}

System.out.print(" ");

}

}

/**

* Method that displays the view by month calendar to the user

*/

public void navigateCalendar() {

GregorianCalendar cal = new GregorianCalendar();

realMonth = cal.get(GregorianCalendar.MONTH);

realYear = cal.get(GregorianCalendar.YEAR);

System.out.println(monthDisplay(currentMonth) + " " + realYear);

displayWeekdays();

System.out.print(" ");

int todaysDate = cal.get(GregorianCalendar.DAY_OF_MONTH);

int EventMonths = 0;

for (int row = 0; row < EventCalendar.length; row++) {

for (int column = 0; column < EventCalendar[0].length; column++) {

if (EventCalendar[row][column] != null) {

if (EventCalendar[row][column].getDay() == todaysDate && realMonth == currentMonth) {

for (int i = 0; i < EventDays.size(); i++) {

EventMonths = EventDays.get(i).getMonth();

if (EventDays.get(i).getDay() == EventCalendar[row][column].getDay()

&& EventMonths == currentMonth + 1) {

EventStored[row][column] = "[" + EventCalendar[row][column].getDay() + "]" + "";

break;

} else {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " " + "";

}

}

if (EventStored[row][column] == null) {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " ";

}

System.out.print(EventCalendar[row][column].getDay() + " ");

}

if (EventCalendar[row][column].getDay() == todaysDate && realMonth != currentMonth) {

for (int i = 0; i < EventDays.size(); i++) {

EventMonths = EventDays.get(i).getMonth();

if (EventDays.get(i).getDay() == EventCalendar[row][column].getDay()

&& EventMonths == currentMonth + 1) {

EventStored[row][column] = "[" + EventCalendar[row][column].getDay() + "]" + "";

break;

} else {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " " + "";

}

}

if (EventStored[row][column] == null) {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " ";

}

System.out.print(" " + EventCalendar[row][column].getDay() + " ");

}

if (EventCalendar[row][column].getDay() != todaysDate && EventCalendar[row][column].getDay() == 0) {

for (int i = 0; i < EventDays.size(); i++) {

EventMonths = EventDays.get(i).getMonth();

if (EventDays.get(i).getDay() == EventCalendar[row][column].getDay()

&& EventMonths == currentMonth + 1) {

EventStored[row][column] = "[" + EventCalendar[row][column].getDay() + "]" + "";

break;

} else {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " " + "";

}

}

System.out.print(" ");

} else if (EventCalendar[row][column].getDay() != todaysDate

&& EventCalendar[row][column].getDay() < 10) {

for (int i = 0; i < EventDays.size(); i++) {

EventMonths = EventDays.get(i).getMonth();

if (EventDays.get(i).getDay() == EventCalendar[row][column].getDay()

&& EventMonths == currentMonth + 1) {

EventStored[row][column] = "[" + EventCalendar[row][column].getDay() + "]" + "";

break;

} else {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " ";

}

}

if (EventStored[row][column] == null) {

EventStored[row][column] = " " + EventCalendar[row][column].getDay() + " ";

}

System.out.print(EventStored[row][column]);

} else if (todaysDate != EventCalendar[row][column].getDay()) {

for (int i = 0; i < EventDays.size(); i++) {

EventMonths = EventDays.get(i).getMonth();

if (EventDays.get(i).getDay() == EventCalendar[row][column].getDay()

&& EventMonths == currentMonth + 1) {

EventStored[row][column] = "[" + EventCalendar[row][column].getDay() + "]" + "";

break;

} else {

EventStored[row][column] = EventCalendar[row][column].getDay() + " ";

}

}

if (EventStored[row][column] == null) {

EventStored[row][column] = EventCalendar[row][column].getDay() + " ";

}

System.out.print(EventStored[row][column]);

}

} else if (EventCalendar[row][column] == null) {

System.out.print(" ");

}

}

System.out.print(" ");

}

}

/**

* Method that subtracts the month of the view month calendar

*/

public void subtractMonth() {

if (currentMonth == 0) {

currentMonth = 11;

currentYear -= 1;

} else {

currentMonth -= 1;

}

Day d = new Day(currentMonth, 1, currentYear);

fillEventCalendar(d);

navigateCalendar();

}

/**

* Method that adds the month of the view month calendar

*/

public void addMonth() {

if (currentMonth == 11) {

currentMonth = 0;

currentYear += 1;

} else {

currentMonth += 1;

}

Day d = new Day(currentMonth, 1, currentYear);

fillEventCalendar(d);

navigateCalendar();

}

/**

* This method displays the current day information of the current day

*

* This method will throw an exception if the entered date is not in the

* correct format

*

* @param days

* The day to display

* @param months

* The month to display

* @param weekInfo

* The weekday the day starts on

* @throws ParseException

*/

public void todaysWeekinfo(int days, int months, int weekInfo) throws ParseException {

int month = months + 1;

int realweekInfo = weekInfo - 1;

String[] allweekDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

String[] allmonths = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

System.out.println(allweekDays[realweekInfo] + " " + allmonths[months] + " " + days + ", " + currentYear);

String dateString = month + "/" + currentDay + "/" + currentYear;

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

if (Events.containsKey(x)) {

System.out.println(Events.get(x));

}

}

/**

* This method gets the current day information

*

* This method will throw an exception if entered date is not in the correct

* format

*

* @throws ParseException

*/

public void currentDay() throws ParseException {

GregorianCalendar cal = new GregorianCalendar();

int todays = cal.get(GregorianCalendar.DATE);

currentDay = todays;

int weekInfo = cal.get(GregorianCalendar.DAY_OF_WEEK);

todaysWeekinfo(todays, currentMonth, weekInfo);

}

/**

* This method subtracts the day info for day view

*

* This method will throw an exception if entered day is not in the correct

* format

*

* @throws ParseException

*/

public void subtractDay() throws ParseException {

if (currentDay == 1) {

currentMonth -= 1;

GregorianCalendar x = new GregorianCalendar(currentYear, currentMonth, 1);

AllDaysOfMonth = x.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);

weekDayInfo = x.getActualMaximum(GregorianCalendar.DAY_OF_WEEK);

weekDayInfo -= 1;

currentDay = AllDaysOfMonth;

} else {

currentDay -= 1;

GregorianCalendar x = new GregorianCalendar(currentYear, currentMonth, currentDay);

weekDayInfo = x.get(GregorianCalendar.DAY_OF_WEEK);

weekDayInfo -= 1;

}

subtractWeekDayInfo(weekDayInfo, currentMonth);

}

/**

* This method adds the day info for day view

*

* This method will throw an exception if entered day is not in the correct

* format

*

* @throws ParseException

*/

public void addDay() throws ParseException {

if (currentDay == AllDaysOfMonth) {

currentMonth += 1;

currentDay = fDayOfMonth;

} else {

currentDay += 1;

GregorianCalendar x = new GregorianCalendar(currentYear, currentMonth, currentDay);

weekDayInfo = x.get(GregorianCalendar.DAY_OF_WEEK);

weekDayInfo -= 1;

}

addWeekDayInfo(weekDayInfo, currentMonth);

}

/**

* This method displays the added day view information based on the addDay()

* method

*

* This method throws an exception if the entered day is not in the correct

* format

*

* @param days

* The day to display

* @param months

* The month to display

*

* @throws ParseException

*/

public void addWeekDayInfo(int days, int months) throws ParseException {

int month = months + 1;

String[] allweekDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

String[] allmonths = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

System.out.println(allweekDays[days] + " " + allmonths[months] + " " + (currentDay) + ", " + currentYear);

String dateString = month + "/" + currentDay + "/" + currentYear;

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

if (Events.containsKey(x)) {

Event e = (Event) Events.get(x);

System.out.println(e.getName() + " " + e.getDate() + " " + e.getTime());

}

}

/**

* This method displays the subtracted day view information based on the

* subtractDay() method

*

* This method throws an exceptionif the entered day is not in the correct

* format

*

* @param days

* The day to display

* @param months

* The month to display

*

* @throws ParseException

*/

public void subtractWeekDayInfo(int days, int months) throws ParseException {

int month = months + 1;

String[] allweekDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

String[] allmonths = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

System.out.println(allweekDays[days] + " " + allmonths[months] + " " + currentDay + ", " + currentYear);

String dateString = month + "/" + currentDay + "/" + currentYear;

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

if (Events.containsKey(x)) {

Event e = (Event) Events.get(x);

System.out.println(e.getName() + " " + e.getDate() + " " + e.getTime());

}

}

/**

* This method creates an event

*

* This method throws an exception if date entered is not in the correct

* format

*

* @param d

* The day the event is on

* @param e

* The event to add

*

* @throws ParseException

*/

public void createEvent(Day d, Event e) throws ParseException {

String dateString = e.getDate() + " " + e.getTime();

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = new GregorianCalendar();

x.setTime(parsed);

Events.put(x, e);

Day eventDay = new Day(d.getMonth(), d.getDay(), d.getYear());

EventDays.add(eventDay);

}

/**

* This method goes to the day entered and displays event on the day

*

* This method throws an exception if date entered is not in the correct

* format

*

* @param d

* The day to go to

* @throws ParseException

*/

public void goToEvent(Day d) throws ParseException {

String dateString = d.getMonth() + "/" + d.getDay() + "/" + d.getYear();

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

if (Events.containsKey(x)) {

int findWeekDay = x.get(GregorianCalendar.DAY_OF_WEEK);

currentDay = d.getDay();

currentYear = d.getYear();

displayGoToEvent(findWeekDay, d.getMonth());

Event e = (Event) Events.get(x);

System.out.println(e.getName() + " " + e.getDate() + " " + e.getTime());

}

}

/**

* This method displays the header for the goToEvent() method

*

* @param days

* The day to display

* @param months

* The month to display

*/

public void displayGoToEvent(int days, int months) {

int today = days - 1;

int month = months - 1;

String[] allweekDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

String[] allmonths = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

System.out.println(allweekDays[today] + " " + allmonths[month] + " " + currentDay + ", " + currentYear);

}

/**

* This method displays the list of events for

*

* This method throws an exception if the dates are not in the correct

* format

*

* @throws ParseException

*/

public void eventList() throws ParseException {

List sortedKeys = new ArrayList(Events.keySet());

Collections.sort(sortedKeys);

for (int i = 0; i < sortedKeys.size(); i++) {

if (Events.containsKey(sortedKeys.get(i))) {

Event e = (Event) Events.get(sortedKeys.get(i));

String dateString = e.getDate() + " " + e.getTime();

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

System.out.println(x.get(GregorianCalendar.YEAR));

System.out.println(e.getName() + " " + e.getDate() + " " + e.getTime());

}

}

}

/**

* This method deletes a day event

*

* This method throws an exception if entered date is not in the correct

* format

*

* @param d

* The day to delete

*

* @throws ParseException

*/

public void selectDeleteEvent(Day d) throws ParseException {

String dateString = d.getMonth() + "/" + d.getDay() + "/" + d.getYear();

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

if (Events.containsKey(x)) {

Events.remove(x);

}

for (int i = 0; i < EventDays.size(); i++) {

if (d.getDay() == EventDays.get(i).getDay() && d.getMonth() == EventDays.get(i).getMonth()

&& d.getYear() == EventDays.get(i).getYear()) {

EventDays.remove(i);

}

}

}

/**

* This method simply deletes all events

*/

public void deleteAll() {

Events.clear();

EventDays.clear();

for (int row = 0; row < EventCalendar.length; row++) {

for (int column = 0; column < EventCalendar[0].length; column++) {

EventCalendar[row][column] = null;

Day d = new Day(currentMonth, currentDay, currentYear);

fillEventCalendar(d);

}

}

}

/**

* This method loads events into the hashmap

*

* This method throws an exception if the events are not in the correct

* format

*

* @param filename

* The file to load

* @throws ParseException

*/

public void loadFile(File filename) throws ParseException {

try {

Scanner in = new Scanner(filename);

while (in.hasNext()) {

String dateString = in.nextLine();

String Title = dateString.substring(0, dateString.indexOf(" "));

String Date = dateString.substring(dateString.indexOf(" ") + 1, dateString.length());

String Time = Date.substring(Date.indexOf(" ") + 1, Date.length());

String EventDate = Date.substring(0, Date.indexOf(" "));

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(Date);

GregorianCalendar x = (GregorianCalendar) GregorianCalendar.getInstance();

x.setTime(parsed);

Event e = new Event(Title, EventDate, Time);

Events.put(x, e);

int month = x.get(GregorianCalendar.MONTH);

Day d = new Day(month, x.get(GregorianCalendar.DATE), x.get(GregorianCalendar.YEAR));

EventDays.add(d);

}

} catch (FileNotFoundException e) {

System.out.print("Could not find File");

}

}

/**

* This method writes out to file

*

* @param filename

* The file to write out to

* @throws ParseException

*/

public void writeToFile(File filename) throws ParseException {

try {

PrintWriter out = new PrintWriter(filename);

{

{

List sortedKeys = new ArrayList(Events.keySet());

Collections.sort(sortedKeys);

for (int i = 0; i < sortedKeys.size(); i++) {

if (Events.containsKey(sortedKeys.get(i))) {

Event e = (Event) Events.get(sortedKeys.get(i));

String dateString = e.getDate() + " " + e.getTime();

DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Date parsed = df.parse(dateString);

GregorianCalendar x = new GregorianCalendar();

x.setTime(parsed);

out.write(e.getName() + " " + e.getDate() + " " + e.getTime());

out.write(" ");

}

}

out.close();

}

}

} catch (FileNotFoundException e) {

System.out.println("Unable to save information");

}

}

}

Day.java

public class Day {

private int Month;

private int Day;

private int Year;

/**

* Date of the day

*

* @param Month

* The month entered

* @param Day

* The day entered

* @param Year

* The year entered

*/

public Day(int Month, int Day, int Year) {

this.Month = Month;

this.Day = Day;

this.Year = Year;

}

/**

* This method returns the month entered by user

*

* @return The month to return

*/

public int getMonth() {

return Month;

}

/**

* This method returns the day entered by user

*

* @return The day to return

*/

public int getDay() {

return Day;

}

/**

* This method returns the year entered by user

*

* @return The year to return

*/

public int getYear() {

return Year;

}

}

Event.java

public class Event extends ArrayList<Event> {

private String Name;

private String Date;

private String Time;

/**

* An Event's information

*

* @param Name

* The title of the event

* @param Date

* The date of the event

* @param Time

* The time of the event

*/

public Event(String Name, String Date, String Time) {

this.Name = Name;

this.Date = Date;

this.Time = Time;

}

/**

* This method returns the name of the event

*

* @return The name to return

*/

public String getName() {

return Name;

}

/**

* This method returns the date of the event

*

* @return The date to return

*/

public String getDate() {

return Date;

}

/**

* This method returns the time of the event

*

* @return The time to return

*/

public String getTime() {

return Time;

}

public String toString() {

return Name + Date + Time;

}

}

MyCalendarTester.java

public class MyCalendarTester {

public static void main(String[] args) throws ParseException {

try {

String file = args[0];

File filename = new File(file);

File newFile = new File("events.txt");

boolean checkInputFile = filename.exists();

CalendarManager Calendar = new CalendarManager();

if (checkInputFile) {

Scanner in = new Scanner(filename);

while (in.hasNext()) {

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

String choice = in.nextLine();

if (choice.equals("L")) {

boolean checkExistingFile = newFile.exists();

if (checkExistingFile) {

Calendar.loadFile(newFile);

}

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("V")) {

System.out.println("[D]ay view or [M]view ? ");

choice = in.nextLine();

if (choice.equals("M")) {

Calendar.navigateCalendar();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

while (choice.equals("P")) {

Calendar.subtractMonth();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

while (choice.equals("N")) {

Calendar.addMonth();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

if (choice.equals("M")) {

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

}

if (choice.equals("D")) {

Calendar.currentDay();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

while (choice.equals("P")) {

Calendar.subtractDay();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

while (choice.equals("N")) {

Calendar.addDay();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

if (choice.equals("M")) {

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

}

}

if (choice.equals("C")) {

System.out.println("Title: ");

String Title = in.nextLine();

System.out.println("Date: ");

String Date = in.nextLine();

Scanner in3 = new Scanner(Date);

in3.useDelimiter("/");

int Month = in3.nextInt();

int Day = in3.nextInt();

int Year = in3.nextInt();

System.out.println("Time: ");

String Time = in.nextLine();

Day addDay = new Day(Month, Day, Year);

Event addEvent = new Event(Title, Date, Time);

Calendar.createEvent(addDay, addEvent);

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("G")) {

System.out.println("Date: MM/DD/YYYY");

String Date = in.nextLine();

Scanner in3 = new Scanner(Date);

in3.useDelimiter("/");

int Month = in3.nextInt();

int Day = in3.nextInt();

int Year = in3.nextInt();

Day goToDay = new Day(Month, Day, Year);

Calendar.goToEvent(goToDay);

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("E")) {

Calendar.eventList();

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("D")) {

System.out.println("[S]elected or [A]ll ?");

choice = in.nextLine();

if (choice.equals("S")) {

String Date = in.nextLine();

Scanner in3 = new Scanner(Date);

in3.useDelimiter("/");

int Month = in3.nextInt();

int Day = in3.nextInt();

int Year = in3.nextInt();

Day deleteDay = new Day(Month, Day, Year);

Calendar.selectDeleteEvent(deleteDay);

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("A")) {

Calendar.deleteAll();

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

}

if (choice.equals("Q")) {

Calendar.writeToFile(newFile);

}

}

} else {

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

Scanner in = new Scanner(System.in);

while (in.hasNext()) {

String choice = in.nextLine();

if (choice.equals("L")) {

boolean checkExistingFile = newFile.exists();

if (checkExistingFile) {

Calendar.loadFile(newFile);

}

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("V")) {

System.out.println("[D]ay view or [M]view ? ");

choice = in.nextLine();

if (choice.equals("M")) {

Calendar.navigateCalendar();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

while (choice.equals("P")) {

Calendar.subtractMonth();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

while (choice.equals("N")) {

Calendar.addMonth();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

if (choice.equals("M")) {

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

}

if (choice.equals("D")) {

Calendar.currentDay();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

while (choice.equals("P")) {

Calendar.subtractDay();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

while (choice.equals("N")) {

Calendar.addDay();

System.out.println("[P]revious or [N]ext or [M]ain menu ?");

choice = in.nextLine();

}

if (choice.equals("M")) {

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

}

}

if (choice.equals("C")) {

System.out.println("Title: ");

String Title = in.nextLine();

System.out.println("Date: ");

String Date = in.nextLine();

Scanner in3 = new Scanner(Date);

in3.useDelimiter("/");

int Month = in3.nextInt();

int Day = in3.nextInt();

int Year = in3.nextInt();

System.out.println("Time: ");

String Time = in.nextLine();

Day addDay = new Day(Month, Day, Year);

Event addEvent = new Event(Title, Date, Time);

Calendar.createEvent(addDay, addEvent);

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("G")) {

System.out.println("Date: MM/DD/YYYY");

String Date = in.nextLine();

Scanner in3 = new Scanner(Date);

in3.useDelimiter("/");

int Month = in3.nextInt();

int Day = in3.nextInt();

int Year = in3.nextInt();

Day goToDay = new Day(Month, Day, Year);

Calendar.goToEvent(goToDay);

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("E")) {

Calendar.eventList();

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("D")) {

System.out.println("[S]elected or [A]ll ?");

choice = in.nextLine();

if (choice.equals("S")) {

String Date = in.nextLine();

Scanner in3 = new Scanner(Date);

in3.useDelimiter("/");

int Month = in3.nextInt();

int Day = in3.nextInt();

int Year = in3.nextInt();

Day deleteDay = new Day(Month, Day, Year);

Calendar.selectDeleteEvent(deleteDay);

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

if (choice.equals("A")) {

Calendar.deleteAll();

Calendar.printCalendar();

System.out.println("Select one of the following options: ");

System.out.println("[L]oad [V]iew by [C]reate [G]o to [E]vent list [D]elete [Q]uit");

}

}

if (choice.equals("Q")) {

Calendar.writeToFile(newFile);

}

}

}

} catch (FileNotFoundException e) {

System.out.print("No File");

}

}

}