mardi 3 mars 2015

Problems with method and if/switch statements [on hold]


Having a hard time getting this to work. What I'm trying to get is a confirmation via boolean that the date entered as (ex; 1 1 2000) is correct or (1 1 3000) is incorrect, and print invalid year or month. Then, I was trying to use a switch statement for the validation of day. However, I need a return value at the end, so I tried setting a boolean variable, but that still didn't work. 10 hours of looking at this, and I can't get it. Any suggestions? Thank you! Apologies of the mess. It's been a rough night.



public static boolean Date(int month, int day, int year) {
boolean statement;
if (year<1582||(year>=2015&&month>3&&day>8))
System.out.println("Invalid year.");
statement = false;
else if ((month>12)||(month<1))
System.out.println("Invalid month.");
statement = false;
else
switch(day) {
case 1-28:
if (month==1||month==2||month==3||month==4||month==5||month==6
||month==7||month==8||month==9||month==10||month==11||month==12)
statement =true;

else if(month==1||month==3||month==4||month== 5||month==6||month==7
||month==8||month==9||month==10||month==11||month==12)
statement =true;

case 29:
if (month==2)
statement = isLeapYear(year);

else if (month==1||month==3||month==4||month==5||month==6||month==7
||month==8||month==9||month==10||month==11||month==12)
statement =true;

case 30:
if (month==2)
//statement = false;
statement = false;

else if (month==1||month==3||month==4||month==5||month==6 ||month==7
||month==8||month==9||month==10||month==11||month==12)
//statement= true;
statement = true;

case 31:
if (month==1||month==2||month==4||month==6||month==9||month==11)
//statement = false;
statement =true;

else if
(month==3||month==5||month==7||month==8||month==10||month==12)
//statement=true;

statement = true;

}
return statement;
}




Aucun commentaire:

Enregistrer un commentaire