I am on a project that requires me of the following:
Validate date input by user without use of
Date
library. (Able to do)Prints the next date of the user input date if valid date is typed in. Example: User input 28 Feb 2010. Display 01 Mar 2010 as tomorrow's date. (To-Do)
Asks user if he/she wishes to continue at the end of the program. (To-Do)
Current additional problems:
Unable to retrieve
dateValid
boolean value from above if/else statements.Unable to prompt user if he/she wishes to continue at the end of the output.
Below is a sample of my code.
I would like to request for assistance.
Any help will be greatly appreciated
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
boolean dateValid;
System.out.println ("Enter the day: ");
int day = scan.nextInt();
System.out.println ("Enter the month: ");
int month = scan.nextInt();
System.out.println ("Enter the year: ");
int year = scan.nextInt();
if (month <= 1 && month >= 12) //checks validity for user month input
{
dateValid=false;
}
else if((month==1) && (day>=1 && day<=31)) //the following are checks for each month, base on the number of days, including leap year check for Feb
{
dateValid=true;
}
//same if/else for the next few months
if (dateValid=true) //unable to get dateValid boolean value from above if/else statements
{
//TO-DO Print tomorrow's date
//TO-DO Prompts user if he wishes to continue (Y/N?)
}
else
{
System.out.println("DATE INVALID");
//TO-DO Prompts user if he wishes to continue (Y/N?)
}
}
Aucun commentaire:
Enregistrer un commentaire