DATE PROGRAM
Date Class:
{
private int month;
private int year;
private int day;
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public void displayDate()
{
System.out.print(getMonth()+ "/" +getDay()+ "/" +getYear() ) ;
}
}
Date Test Class:
public class DateTest
{
public static void main (String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the day");
int d=in.nextInt();
System.out.println("Enter the month ");
int m=in.nextInt();
System.out.println("Enter the year ");
int y=in.nextInt();
Date date=new Date();
date.setDay(d);
date.setMonth(m);
date.setYear(y);
date.displayDate();
}
}
Comments