CS120 Project 4

Improving the simple date calculator

Overview. Five hundred and thirty days after May 15, 2018, what date will it be? In this assignment, you will use classes to model dates.

Technical details. In Tuesday’s lab exercise, you started a class Day for representing dates as objects. Here is a similar class, which includes one additional constructor, and one additional method, in addition to the ones you started in the exercise. Complete this class (incorporating the work you have already done in the lab exercise) so that the methods all work as described. Your class and methods should work correctly for all years and days — including leap years — in the Gregorian calendar.

Testing these assignments. I will write a program to test your code by creating Day objects with the two constructors, and calling the five methods to check 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 Friday, December 1. Remember to comply with the style guidelines for CS120 Java work.

Optional extra challenge. As an optional extra challenge, add one more method to your class,

public String dayOfWeek()

The dayOfWeek method should return the name of the day of the week (Sunday, Monday, etc.) which this Day is. This webpage has a good discussion of how to calculate the day of the week for an arbitrary date. (This method will not be graded at all; it is strictly an interesting further exercise.)

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