You are on page 1of 5

WordPress

DigiSkill.com

EX 2
Submitted By:
Syed Komail

Topics:
Exercise no 2

Figure 1 Final View

public class date


{

private int day;

private int month;

private int year;

public date()

{ public class datetest

} public static void main(String args[])


public date(int dy,int mn,int yr) {
{ System.out.println("The value of dat month and year for d1 is\n");
setday(dy);
date d1=new date(17,9,2015);
//day=dy;
d1.displaydate();
setmonth(mn);
System.out.println("The value of dat month and year for d2 is\n");
//month=mn;
date d2=new date(23,12,2019);
setyear(yr);
d2.displaydate();
//year=yr;
System.out.println("The value of dat month and year for d3 is\n");
}
date d3=new date(d2);
public date(date d2)
d3.displaydate();
{
System.out.println("The value of dat month and year for d4 is\n");
day=d2.day;
date d4=new date(2018);
setday(day);
d4.displaydate();
month=d2.month;
System.out.println("The value of dat month and year for d5 is\n");
setmonth(month);
date d5=new date(2018,10);
year=d2.year;
d5.displaydate();
setyear(year);
System.out.println("The value of day month and year for d3 set
}
again\n");
public date(int yr)
d3.setdate(d4);
{
d3.displaydate();
setyear(yr);

//year=yr;

month=1;

day=1; }
}
}
public date(int mn,int yr)

setmonth(mn);
//month=mn;

setyear(yr);

//year=yr;

day=1;

public void setday(int dy)

if (dy<=31&&dy>0)

day=dy;

else

System.out.println("Invalid access");

day=1;

public void setmonth(int mn)

if (mn<=12&&mn>0)

month=mn;

else

System.out.println("Invalid access");

month=1;

public void setyear(int yr)

if(yr>0)

year=yr;

}
else

System.out.println("Invalid access");

year=1;

public void setdate(int dy,int mn,int yr)

setday(dy);

//day=dy;

setmonth(mn);

//month=mn;

setyear(yr);

//year=yr;

public void setdate(date d3)

day=d3.day;

setday(day);

month=d3.month;

setmonth(month);

year=d3.year;

setyear(year);

public int getday()

return day;

public int getmonth()

return month;

public int getyear()

return year;

}
public void displaydate()

System.out.println("\nThe value of day is\n"+day+"\nThe value of month is\n"+month+"\nthe value of year


is\n"+year);

You might also like