第二部分,它说,新的订单,如果我把'5'也会说"请选择一个有效的选择"和循环回到"欢迎来到脚----"的一部分。
我怎么得到它的唯一环,回到他们在那里输入错误提示?
例如:如果我输入5,它会说"请选择有效的选择",然后显示的"新秩序"一部分,而不是"欢迎来---"
public static void main(String[] args) {
Assignment2A_JasmineLimSmithh myref = new Assignment2A_JasmineLimSmithh();
while (true) {
myref.run();
}
}
void run() {
System.out.println("Welcome to Foot Loose Reflexology");
System.out.println("Main Menu \n 1. add new order \n 2. update order \n 3. view all orders \n 4. exit");
System.out.print("Enter your choice [1...4] ");
int a = 0;
try {
a = scan.nextInt();
} catch (Exception e) {
System.out.println("Please choose a valid option!");
return;
}
if (a > 4 || a < 1) {
System.out.println("Please choose a valid option!");
return;
}
if (a == 1)
newOrder();
else if (a == 2)
updateOrder();
else if (a == 3)
displayOrders();
else if (a == 4)
System.exit(0);
}
void newOrder() {
int name, choices = 0, duration = 0, order;
System.out.println();
do { // check for space?
System.out.println("Add new order \n Reflexologist name: \n 1. Mark \n 2. James \n 3. Lily");
System.out.print("Enter your choice [1...3] ");
try {
name = scan.nextInt();
} catch (Exception e) {
System.out.println("Please choose a valid option!");
return;
}
if (name > 3 || name < 1) {
System.out.println("Please choose a valid option!");
return;
}
} while (name > 3 || name < 1);