Vous êtes sur la page 1sur 5

class Date { private int month; // 1-12 private int day; // 1-31 based on month private int year;

// any year public void setdate( int theMonth, int theDay, int theYear ) { DataInputStream d=new DataInputStream(System.in); int daysPerMonth[] ={ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; while(!(theMonth > 0 && theMonth <= 12) ) { System.out.println("please enter the correct month \n"); theMonth=Integer.parseInt(d.readLine()); } month=theMonth; //check whether the day is within the range while(!(theDay > 0 && theDay <= daysPerMonth[ month ])) { System.out.println("please enter the correct date \n"); theday=Integer.parseInt(d.readLine()); } //check for leap year while(!(month == 2 && testDay == 29 && ( year % 400 == 0 ||( year % 4 == 0 && year % 100 != 0 ) ) )) { System.out.println("please enter the correct date \n"); theday=Integer.parseInt(d.readLine()); } day=theDay; year = theYear; } // end setdate

public String toString() { return (day+"/"+month+"/"+year); } // end method toString } // end class Date class address { private private private private String saddr; String city; String state; long zip;

address() { saddr=" "; city=" "; state=" "; zip=" "; } public void setsaddr(String t) { saddr=t; } public void setcity(String t) { city=t; } public void setstate(String t) { state=t; } public void setzip(int t) { zip=t; } public String getsaddr() { return saddr; } public String getcity() { return city; } public String getstate() { return state; } public long getzip() { return zip; } public String toString() { return (saddr+" "+city+" "+state+" "+zip); } } class person {

private String fname; private String lname; private Date dt; private address sd; public void setdate(int m,int d,int y) { dt.setdate(m,d,y); } public void setfname(String t) { fname=t; } public void setlname(String t) { lname=t; } public String getlname() { return lname; } public String getfname() { return fname; } public String toString() { return (fname+" "+lname); }

} class extperson extends person { private String rel; private String ph; public void setrel(String t) { rel=t; } public void setph(String t) { ph=t; } public String getrel() { return rel;

} public String getph() { return ph; }

} class ab { public static void main(String args[]) { int n; String fname,lname; int d,m,y; try { DataInputStream t=new DataInputStream(System.in); extperson e[]=new extperson[1000]; System.out.println("for how many persons you want to enter the dat a\n"); n=Integer.parseInt(t.readLine()); for(i=0;i<n;i++) { e[i]=new extperson(); System.out.println("enter the details of the person"+( i+1)); System.out.println("enter the fname "); fname=t.readLine(); e[i].setfname(fname); System.out.println("enter the lname "); lname=t.readLine(); e[i].setlname(lname); System.out.println("enter the day of your birth"); d=Integer.parseInt(t.readLine()); System.out.println("enter the month of your birth"); m=Integer.parseInt(t.readLine()); System.out.println("enter the year of your birth"); y=Integer.parseInt(t.readLine()); e[i].setdate(m,d,y);

} } catch(Exception e) { } }

Vous aimerez peut-être aussi