diff --git a/src/nyc/c4q/ac21/calendar/CalendarPrinter.java b/src/nyc/c4q/ac21/calendar/CalendarPrinter.java index 74f7a5e..f818c9e 100644 --- a/src/nyc/c4q/ac21/calendar/CalendarPrinter.java +++ b/src/nyc/c4q/ac21/calendar/CalendarPrinter.java @@ -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. + } + } diff --git a/src/nyc/c4q/ac21/calendar/DateTools.java b/src/nyc/c4q/ac21/calendar/DateTools.java index e391fd7..7ebc94e 100644 --- a/src/nyc/c4q/ac21/calendar/DateTools.java +++ b/src/nyc/c4q/ac21/calendar/DateTools.java @@ -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)); @@ -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. @@ -64,13 +64,47 @@ public static Calendar getNextDay(Calendar cal) { */ public static HashMap getDayOfWeekNames() { HashMap names = new HashMap(); + 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 getMonthNames() { + HashMap names = new HashMap(); + 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)); } } diff --git a/src/nyc/c4q/ac21/calendar/Main.java b/src/nyc/c4q/ac21/calendar/Main.java index 8e1fa0d..d390ea5 100644 --- a/src/nyc/c4q/ac21/calendar/Main.java +++ b/src/nyc/c4q/ac21/calendar/Main.java @@ -21,6 +21,7 @@ public static void main(String[] args) { // 1. Show the day of the week. HashMap dayOfWeekNames = DateTools.getDayOfWeekNames(); + // ... // 2. Show whether this is a work day.