CS120 Project 3

Overview. Fifty days after May 15, 2018, what date will it be? In this assignment, you will improve your previous simple date calculator by:

  • Using a methods for date formatting and for date calculation.
  • Using an array (or several arrays) to reduce the complexity of your code.

Technical details. Your DateCalc class should include two static methods,

/** Given a month and date, return the string representing the
 * date which they represent.  For example, a call to
 * <code>formatDate(2,5)</code> should return the string
 * <code>February 5</code>.
 *
 * @param month Number of a month, from 1 (for January) to 12
 * @param date Number of a month, from 1 up to the maximum for the
 * given month
 */
public static String formatDate(int month, int date) {
  // ...your code goes here...
}
/** Given a month and date and a number of days, return the string
 * representing the date <code>days</code> later than the date
 * represented by the given month and date.  For example, a call
 * to <code>formatDate(2,5,10)</code> should return the string
 * <code>February 15</code>.
 *
 * @param month Number of a month, from 1 (for January) to 12
 * @param date Number of a month, from 1 up to the maximum for the
 * given month
 * @param days A number of days
 */
public static String addToDate(int month, int date, int days) {
  // ...your code goes here...
}

Neither of these methods should print anything. They return a string value, which the caller may decide to print, or may use in some other way.

You should store information about the structure of a year in arrays, and use those arrays in your code to simplify your earlier methods.

For this assignment, you can again assume that all of the numbers will be in their sensible, natural ranges, that it is not a leap year, and that the number of days will not “wrap around” from December back to January.

Do not give a Java package declaration in your class (and if you do not know what that means, do not worry about it!).

Testing these assignments. I will write a program to test your code by calling those two static methods and examining their results. Note that I will not run your main routine, so you can use it for your own testing purposes.

Submission instructions. Submit the single, plain-text file DateCalc.java to D2L by 8:30am on Monday, October 30. Remember to comply with the style guidelines for CS120 Java work.

Avoid plagiarism. The course syllabus has further details about our expectations of academic integrity. In particular: You may not copy code from any other source and claim it as your own. You may not share any of your code with any other student for use in completing any of these assignments.

Links to: CS120 homepage