All pastes #220192 Raw Edit

jeremy's changes

public java v1 · immutable
#220192 ·published 2006-10-25 02:03 UTC
rendered paste body
public class Student implements Comparable<Student> {//	student id, 1-1000	int sid;	Birthday sbirthday;//	constructor 	public Student(int id, Birthday.Month month, int date){ 		this.sid = id;		this.sbirthday = new Birthday();		this.sbirthday.month = month ;		this.sbirthday.date = date;	} //	compare the student according to their birthday. 	public int compareTo(Student s) {		if (this.sbirthday.month.compareTo(s.sbirthday.month) < 0){			return -1;		}		else if (this.sbirthday.month.compareTo(s.sbirthday.month) > 0){			return 1;		}		else {			if (this.sbirthday.date > s.sbirthday.date){				return 1;			}			if (this.sbirthday.date < s.sbirthday.date) {				return -1;			}			else {				return 0;			}		}			}//	display the personal information of a student in such form://	id, month of birthday, date of birthday//	e.g. ID: 10, Month: MAY, Date: 11	public void display(){		System.out.println("ID: " + sid + ", Month: " + sbirthday.month + ", Date: " + sbirthday.date);	} 	public static void main(String[] args) {		 Student a = new Student(1, Birthday.Month.JAN, 7);		 Student b = new Student(2, Birthday.Month.APR, 5);		 Student c = new Student(3, Birthday.Month.MAY, 5);		 a.display();		 b.display();		 c.display();		 System.out.println(a.compareTo(b));		 System.out.println(b.compareTo(c));		 System.out.println(a.compareTo(c));		 }	}