I am trying to ensure that my nextday method can add ONE day to the date the user entered and ensure it adds 40 days correctly, taking into account the correct days per month and leap years
public nextday() {
for (int count = 1; count < 40; count++)
;
}
public String toDayDateString() // toDayDateString method {
int countDays = 0;
for (int i = 1; i < getMonth(); i++) {
if (i == 2 && checkLeapYr(getYear()))
countDays += 29;
else
countDays += daysPerMonth[i];
}
countDays += date;
String message = String.format("\n", countDays, getYear());
return message;
}
private Boolean checkLeapYr(int inYear) { // check leap year method.
if (getYear() % 400 == 0 || (getYear() % 4 == 0 && getYear() % 100 != 0))
return true;
else
return false;
}
Below is a menu that is supposed to allow the user to choose to enter a date or quit, but the date is not being accepted correctly.
{
public static void main ( String [] args)
// User selects how they will enter the dates
{
+"(1) Enter the date as MM/DD/YYYY\n"
+"(Any Key) Quit\n";
int input=0;
Date newDate;
do{
String userInput = JOptionPane.showInputDialog(null, menu);
input = Integer.parseInt( userInput);
String outputMessage="";
if ( input = 1)
{
userInput =JOptionPane.showInputDialog(null, "Please enter a date as 02/28/2011");
switch ( input ) // here is where the menu choice will be evaluated
{
case 1 :
token = userInput.split("/");
if (token.length == 3 )
{
newDate = new Date( Integer.parseInt( token[0]),
Integer.parseInt( token[1]), Integer.parseInt( token[2]) );
outputMessage = newDate.toString();
JOptionPane.showMessageDialog(null, outputMessage);
}
break;
case 2:
} while ( input <>1); // this will quit the program when user selects any key other than 1 at the menu.