i did a break from programming for a while and i want to realize why this class doesn't give me the right answer i expect to get:
public class Date
{
private int _day;
private int _month;
private int _year;
public Date(int day, int month, int year)
{
_day=day;
_month=month;
_year=year;
if((day<1||day>31)&&(month<1||month>12)&&(year<1000||year>9999))
{
_day=26;
_month=2;
_year=2019;
}
}
public String toString()
{
return _day+"/"+_month+"/"+_year;
}
public static void main(String[]args)
{
Date test= new Date(5,13,1999);
System.out.println(test.toString());
}
}
When I insert the values to "test" object as (32,5,1999) it prints out 26.2.2019 hen I insert the values as (5,14,1999) it prints out 5.14.1999 and when I insert the values as (5,6,900) it prints out as 5.8.900 why don't I get the default values that I set at the constructor when the user inputs an illegal value (26.2.2019) thank you for your answers :)
Aucun commentaire:
Enregistrer un commentaire