package example;

public class StructDate extends Date {
	private int year;
	private int month;
	private int day;

	public StructDate(int day, int month, int year) {
		assert((day >= 1) && (day <= 31) && (month >= 1) && (month <= 12) && (year > 0));
		this.year = year;
		this.month = month;
		this.day = day;
	}

	@Override
	public int year() {
		return this.year;
	}

	@Override
	public int month() {
		return this.month;
	}

	@Override
	public int day() {
		return this.day;
	}

	@Override
	public int compareTo(Date d) {
		if (this.year < d.year()) {
			return -1;
		} else if (this.year > d.year()) {
			return 1;
		} else {
			if (this.month < d.month()) {
				return -1;
			} else if (this.month > d.month()) {
				return 1;
			} else {
				if (this.day < d.day()) {
					return -1;
				} else if (this.day > d.day()) {
					return 1;
				} else {
					return 0;
				}
			}
		}
	}

	@Override
	public String toString() {
		return this.day + "/" + this.month + "/" + this.year;
	}
	
	public static void main(String[] args) {
		Date era = new StructDate(1,1,1970);
		Date d = new StructDate(13,2,2012);
		
		System.out.print(d);
		int t = d.compareTo(era);
		if (t < 0) {
			System.out.print(" is before ");
		} else if (t > 0) {
			System.out.print(" is after ");
		} else {
			System.out.print(" is same as ");
		}
		System.out.println(era);
		
		d = new StructDate(45,-1,13);
		System.out.println(d);
	}

}
