Assignment Four

Due February 27, 1999 at the beginning of class.

Please turn in your source code and adequate example sessions to test your programs for each of the three parts.

Part A:
Programming project 5.22 on page 205

Part B:
Programming project 5.26 on page 205

Part C:
Fill in the rest of the following class and use it in a main() which exercises its functions.

public class SimpleDate {
// Member variables
  private int month = 1;
  private int day = 1;
  private int year = 1;

// Constructors
  public SimpleDate() {}

  public SimpleDate( int someDay, int someMonth, int someYear) {
    if( dayMonthAgreement( someDay, someMonth) {
      day = someDay;
      month = someMonth;
    }
    if( someYear > 0) {
      year = someYear;
    }
  }

//  The toString function, which is why we built this!
  public String toString() {
    // Write the rest of this code.  Make the string look like "April 2nd, 1984"
    String answer = monthAsString() + " ";
    answer += // put the day here
    answer += // add on the year here.
    return( s);
  }

// Private utility functions:
  private String monthAsString() {
    String answer = ³Unspecified Month²;
    switch( month) {
      // Write the rest of this code
    }
    return( answer);
  }

  private boolean dayMonthAgreement( int aDay, int aMonth) {
    if( (aMonth < 1) || (aMonth > 12)) {
      return( false);
    }
    switch( month) {
      // Write the rest of this code
    }
    return( true);
  }

  private String dayWordEnding() {
    String answer = "";
    switch( day) {
      // Write the rest of this code
    }
    return( answer);
  }
}

The views and opinions expressed in this page are strictly those of the page author.
The contents of this page have not been reviewed or approved by the University of Minnesota.