Hi I am new to this site I have a problem in my DateTest program and it is with the output I know it has to do with the constructors any help would be appreciated I am very new at this please be specfic
import java.util.*;
public class DateRec
{
private int month,day,year;
boolean good;
private static final int[] daysnMonth ={31,28,31,30,31,30,31,31,30,31,30,31};
DateRec ()
{
month = 1;
day = 1;
year = 2008;
}
DateRec (int m,int d,int y)
{
month = m;
day = d;
year = y;
good = validate();
}
public boolean validate ()
{
if (month < 0 && month < 13 && day > 0 && day <= daysnMonth[month] && year >1900 && year < 2009)
return good;
else
return false;
}
public
String myToString()
{
String m = Integer.toString(month); //there must be a
String d = Integer.toString(day); //simpler format
String y = Integer.toString(year);
String s = m + "/" + d + "/" + y;
return s;
}
}
import java.util. *;
public class DateTest
{
public static void main(String[] args)
{
DateRec Datetest = new DateRec();
String s,m,d,y;
int month = 0 ,day = 0,year = 0 ;
Scanner keyboard = new Scanner(System.in);
char ch;
String ans = "y";
while(ans.charAt(0) == 'y' || ans.charAt(0) == 'Y')
{
System.out.print("Please enter the month: ");
m = keyboard.nextLine();
System.out.print("Please enter the day: ");
d = keyboard.nextLine();
System.out.print("Please enter the year: ");
y = keyboard.nextLine();
s = m + d + y;
for(int i = 0; i < s.length(); i++)
{
ch = s.charAt(i);
} // end for
System.out.println("Do you want to continue: Enter <Y>es or <N>o: ");
ans = keyboard.nextLine();
}
DateRec today = new DateRec();
s = today.myToString();
System.out.println(s);
DateRec anyDay = new DateRec(month,day,year);
s = anyDay.myToString();
System.out.println(s);
DateRec noDay = new DateRec(month,day,year);
s = noDay.myToString();
System.out.println("You entered an invalid date:" + s);
}
}