Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/nyc/c4q/ac21/calendar/CalendarPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static void printMonthCalendar(Calendar date) {
// Use these methods to help you:
// DateTools.getMonthNames()
// DateTools.getNextDay() to loop through days in the month.

}


}
40 changes: 37 additions & 3 deletions src/nyc/c4q/ac21/calendar/DateTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static String formatDate(Calendar cal) {
* @return
* The date it represents, or null if the date is incorrectly formatted.
*/
public static Calendar parseDate(String date) {
public static Calendar parseDate(String date) { // -- makes sure input is in proper format
if (date.length() == 10 && date.charAt(4) == '-' && date.charAt(7) == '-') {
try {
int year = Integer.valueOf(date.substring(0, 4));
Expand All @@ -40,7 +40,7 @@ public static Calendar parseDate(String date) {
return new GregorianCalendar(year, month - 1, dayOfMonth);
}
} catch (NumberFormatException exception) {
// Fall through.
// Fall through. -- b/c it is not in proper format
}
}
// Didn't work.
Expand All @@ -64,13 +64,47 @@ public static Calendar getNextDay(Calendar cal) {
*/
public static HashMap<Integer, String> getDayOfWeekNames() {
HashMap<Integer, String> names = new HashMap<Integer, String>();
names.put(Calendar.SUNDAY, "Sunday");
names.put(Calendar.MONDAY, "Monday");
names.put(Calendar.TUESDAY, "Tuesday");
names.put(Calendar.WEDNESDAY, "Wednesday");
names.put(Calendar.THURSDAY, "Thursday");
names.put(Calendar.FRIDAY, "Friday");
names.put(Calendar.SATURDAY, "Saturday");

// FIXME: Write this.
return names;
}

/**
* Builds and returns a map from integers representing days of the month to the names of the days of the month.
* @return
* A map with keys 'Calendar.JANUARY' through 'Calendar.DECEMBER' with corresponding month names as values.
*/
public static HashMap<Integer, String> getMonthNames() {
HashMap<Integer, String> names = new HashMap<Integer, String>();
names.put(Calendar.JANUARY, "January");
names.put(Calendar.FEBRUARY, "February");
names.put(Calendar.MARCH, "March");
names.put(Calendar.APRIL, "April");
names.put(Calendar.MAY, "May");
names.put(Calendar.JUNE, "June");
names.put(Calendar.JULY, "July");
names.put(Calendar.AUGUST, "August");
names.put(Calendar.SEPTEMBER, "September");
names.put(Calendar.OCTOBER, "October");
names.put(Calendar.NOVEMBER, "November");
names.put(Calendar.DECEMBER, "December");

// FIXME: Write this.
return null; // Change this!
return names; // Change this!
}

public static void main(String[] args) {
System.out.println(getDayOfWeekNames());
System.out.println(getDayOfWeekNames().get(Calendar.SUNDAY));
System.out.println(getMonthNames());
System.out.println(getMonthNames().get(Calendar.JANUARY));
}

}
1 change: 1 addition & 0 deletions src/nyc/c4q/ac21/calendar/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void main(String[] args) {

// 1. Show the day of the week.
HashMap<Integer, String> dayOfWeekNames = DateTools.getDayOfWeekNames();

// ...

// 2. Show whether this is a work day.
Expand Down