Ello, got a minor issue that I haven't got a clue on what's going wrong... Snippet of the code:
do{
String third = JOptionPane.showInputDialog(null, "Please enter Year ["+day+"/"+month+"/YY?]");
year = Integer.parseInt (third);
validChoice = validYear(year);
}while(!validChoice);
do{
String goUS = JOptionPane.showInputDialog(null, "Do you want to switch the format to US? [Y/N]");
goUS = goUS.toUpperCase();
char conversion = goUS.charAt(0);
validChoice = validOption(conversion);
switch(conversion){
case 'Y':
if(year < 10)
{
date.append(month).append("/").append(day).append("/" + "200").append(year);
}else{
date.append(month).append("/").append(day).append("/" + "20").append(year);
}
JOptionPane.showMessageDialog(null, date);
break;
case 'N':
if(year < 10)
{
date.append(day).append("/").append(month).append("/" + "200").append(year);
}else{
date.append(day).append("/").append(month).append("/" + "20").append(year);
}
JOptionPane.showMessageDialog(null, date);
break;
default:
JOptionPane.showMessageDialog(null, "Invalid answer! Use Y/N", "Error", JOptionPane.ERROR_MESSAGE);
}}while(!validChoice);
//// METHODS:
public static boolean validYear (int year){
boolean isValid = true;
if(year < 1 || year > 99)
{
isValid = false;
}
return isValid;
}
public static boolean validOption (char conversion){
boolean isValid = true;
if(conversion != 'y' || conversion != 'n')
{
isValid = false;
}
return isValid;
}
The first part, with regards to the year, and with it's associated method, it loops fine if the input is wrong.
The second part, 'goUS', the method's remotely the same thing, checking the char if it's y/n - it works fine with regards to the check and all, but after hitting OK with the correct display of the date, it starts the goUS loop again, and the answers start to concatenate itself from the previous display, and so on. I want the app to just end after displaying the date.
Any help pointing out my flaw would be greatly appreciated.
validOptionmethod.