Assignment #2

In this assignment you will write two separate classes. The main class you will write is a Date class. A second class you will write will be used by the Date class. That second class will be a MonthInfo class. You will then test your Date class by writing a test program in a third file.

The MonthInfo Class

The MonthInfo class, which is not a public class, should have the following members, which are all static.


class MonthInfo
{
      // Return a string of length three representing
      // the month (with is 1-12) and vice-versa
      // Provide a reasonable return value in case of errors.
    public static String getMonth( int month )
    public static int    getMonth( String month )

    public static int daysInMonth( int month, int year )
    private static boolean isLeapYear( int year )
      { return ( year % 400 == 0 ) || ( year % 4 == 0 && year % 100 != 0 ); }
    private static final String monthArray[ ] = { "Jan", ... };
}

The Date Class

Here is the Date class, skeleton:


public class Date
{
  // PUBLIC FUNCTIONALITY
    // Provide three constructors.
    // One takes no parameters, the other two take
    // a month, day, and year, in that order. One of these three-parameter
    // constructors takes the month as an integer, while the other
    // takes it as a string.
 

    // Provide a setDate method that takes three integers:
    // the month, day, and year. There is no return value.
 

    // Provide a toString method that returns a String representation.
 

    // Provide an equals and a compareTo method.
 
    // Provide a dateAfter method that returns the Date after the current Date.
    // Note: the current Date is unchanged.
 

    // Provide a futureDate method that returns the Date in the future.
    // It takes one parameter that tells how many days in the future to look.
    // If the parameter is negative treat it as a zero.
    // Note: the current Date is unchanged.
 
  // PRIVATE INFO
    // Provide three data members: the month, day, and year, represented
    // as integers. The month will range from 1-12, the day from 1-31, and
    // the year from 1 onwards.
}

Note that if the parameters used to modify a Date make no sense (for instance, Feb 31, 1999), you should print a message and use a respectable date.

Test program

Write a test program to verify that Date works. Note that you can write additional mains in each class to test the various components.

What to Submit

For all assignments, you must submit, in hard copy, the complete source code, as well as the required test program and sample output that proves that your program works. You must also submit, on a virus-free floppy, the source code, compiled class files, and sample output, along with a README.txt file that explains everything. The complete package should be in a single folder, with sufficient packaging to avoid the need of a manilla envelope. Email submissions will not be accepted.