// represent a date
// This must be run in Advanced ProfessorJ

public class Date{

  private String month;
  private int day;
  private int year;

  Date (String month, int day, int year){
     this.month = month;
     this.day = day;
     this.year = year;
  }

  // getters

  // return the month of this Date
  public String getMonth(){
    return this.month;
  }

  // return the day of this Date
  public int getDay(){
    return this.day;
  }

  // return the year of this Date
  public int getYear(){
    return this.year;
  }

  //setters

  // set the month of this Date; must be between 1 and 12
  public boolean setMonth(int monthNumber){
    if (monthNumber <= 0 || monthNumber > 12)
       return false;
    else{
       this.month = monthString(monthNumber);
       return true;
    } 
  }

  // set the day of this Date; must be between 1 and 31
  public boolean setDay(int dayNumber){
    if (dayNumber <= 0 || dayNumber > 31)
       return false;
    else{
       this.day = dayNumber;
       return true;
    }
  }

  // set the year of this Date;  must be between 1900 and 2009
  public boolean setYear(int yearNumber){
    if (yearNumber <  1900 || yearNumber > 2009)
       return false;
    else {
       this.year = yearNumber;
       return true;
    }
}

  // return the name of a month given the month number
  private String monthString (int monthNumber){
    
    if (monthNumber == 1)
      return "January";
    else if (monthNumber == 2)
      return "February";
    else if (monthNumber == 3)
      return "March";
    else if (monthNumber == 4)
      return "April";
    else if (monthNumber == 5)
      return "May";
    else if (monthNumber == 6)
      return "June";
    else if (monthNumber == 7)
      return "July";
    else if (monthNumber == 8)
      return "August";
    else if (monthNumber == 9)
      return "September";
    else if (monthNumber == 10)
      return "October";
    else if (monthNumber == 11)
      return "November";
    else if (monthNumber == 12)
      return "December";
    else
      return "Error";               // keep the compiler happy

  }


  // set this Date;  use a number for the month
  public boolean setDate(int monthInt, int day, int year){

    if (dateOK(monthInt, day, year)){
       this.month = monthString(monthInt);
       this.day = day;
       this.year = year;
       return true;
    }
    else
       return false;
  }

  // set this Date; use a string for the month
  public boolean setDate(String monthString, int day, int year){

    if (dateOK(monthString, day, year)){
       this.month = monthString;
       this.day = day;
       this.year = year;
       return true;
    }
    else
        return false;
  }

  // set this date to the default:  Jan 1 of the given year
  public boolean setDate(int year){
    
    setDate(1, 1, year);
    return true;         // this is needed for compiler
  }


  // check that the given date is valid
  private boolean dateOK(int monthInt, int dayInt, int yearInt){
     return (monthInt >= 1 && monthInt <= 12) &&
            (dayInt >= 1 && dayInt <= 31) &&
            (yearInt >= 1900 && yearInt <= 2009);
  }

  // check that the given date is valid
  private boolean dateOK(String monthString, int dayInt, int yearInt){
    return monthOK(monthString) &&
           (dayInt >= 1 && dayInt <= 31) &&
           (yearInt >= 1900 && yearInt <= 2009);
  }

  // check that the given month is valid
  private boolean monthOK(String month){
     return month.equals("January") || month.equals("February") ||
            month.equals("March") || month.equals("April") ||
            month.equals("May") || month.equals("June") ||
            month.equals("July") || month.equals("August") ||
            month.equals("September") || month.equals("October") ||
            month.equals("November") || month.equals("December");
  }
}




class Examples{
  Examples(){
  }
  
  Date d = new Date("March", 24, 2009);
  
  boolean testGetters = (check this.d.getMonth() expect "March") &&
                        (check this.d.getDay() expect 24) &&
                        (check this.d.getYear() expect 2009);
                        
  boolean testSetters = (check this.d.setMonth(4) expect true) &&
                        (check this.d.setDay(13) expect true) &&
                        (check this.d.setYear(2010) expect false) &&
                        (check this.d.setYear(2007) expect true);
                        
 boolean testGetters2 = (check this.d.getMonth() expect "April") &&
                        (check this.d.getDay() expect 13) &&
                        (check this.d.getYear() expect 2007);
                        
 boolean testSetters2 = (check this.d.setDate("March", 24, 2009) expect true) &&
                        (check this.d.getMonth() expect "March") &&
                        (check this.d.setDate(6, 6, 1966) expect true) &&
                        (check this.d.getMonth() expect "June") &&
                        (check this.d.getDay() expect 6) &&
                        (check this.d.getYear() expect 1966) &&
                        (check this.d.setDate(1955) expect true) &&
                        (check this.d.getMonth() expect "January") &&
                        (check this.d.getDay() expect 1) &&
                        (check this.d.getYear() expect 1955);

}


























