Professional Documents
Culture Documents
21bce0427 VL2022230103800 Ast02
21bce0427 VL2022230103800 Ast02
21BCE0427
Java CAT 1
Create a class Date with member variables day, month and year to store the date as numbers where
the day, month and year should be accessed only through methods. Create default constructor,
constructor which accepts values day, month and year member variables, constructor that will
create a new object from an existing Date object. Write a method that will display point in
DD/MM/YYYY. Write a method validate that will check whether the day is between 1 and 31, month
between 1 and 12, year between 1990 and 2002 inclusive. The method should display the details of
errors in the date value or display that the date is valid. Test the class developed with suitable
instructions.
import java.util.*;
class Date
int day,month,year;
day=0;
month=0;
year=0;
day=d;
month=m;
year=y;
if(day>=1&&day<=31)
System.out.println("Day is valid");
else
if(month>=1&&month<=12)
System.out.println("Month is valid");
else
if(year>=1990&&year<=2002)
System.out.println("Year is valid");
else
System.out.println("Date is "+day+"/"+month+"/"+year);
int d,m,y;
d3=d2;//Copy constructor(Object 3)
d3.check();
d3.display();
Output 1:
Output 2:
Output 3: