/** Month.java models a month (name and number).
 * @author Joel Adams, for Alice+Java.
 */

public class Month {
	public Month(int monthNumber) {
		if (monthNumber < 1 || monthNumber > 12) {
			throw new IllegalArgumentException("Month(): bad month number");
		}
		myNumber = monthNumber;
		myName = MONTHS[monthNumber-1];
	}
	
	public Month(String monthName) {
		int index = -1;
		boolean found = false;
		for (int i = 0; i < MONTHS.length && !found; i++) {
			if ( MONTHS[i].equals(monthName) ) {
				index = i;
				found = true;
			}
		}
		if (found) { 
			myName = monthName;
			myNumber = index+1;
		} else {
			throw new IllegalArgumentException("Month(): bad month name");
		}
	}
	
	public int getNumber() { return myNumber; }
	public String getName() { return myName; }
	
	public boolean equals(String name) { return myName.equals(name); }

	public String toString() { return myName; }

	private static String [] MONTHS = {"January", "February", "March",
			                   "April", "May", "June", "July",
			                   "August", "September", "October",
			                   "November", "December" };
	private String myName;
	private int myNumber;
}
