showMainMenu();
mainChoice = input.nextInt();
switch(mainChoice){
case 1 : showConcertCategories();
concertCategories = input.nextInt();
switch(concertCategories){
case 1 : showMusical();
musical = input.nextInt();
switch(musical){
case 1 : showMyFairLady();
myFairLady = input.nextInt();
switch(myFairLady){
case 1 : System.out.print("Please input number of tickets:");
title = "MY FAIR LADY";
date = "20/01/08";
tickets = input.nextInt();
totalPrice = 90 * tickets;
System.out.println("\nBooking Information <All concerts begin at 8pm>");
System.out.println("-----------------------------------------------");
System.out.println("Concert: MY FAIR LADY");
System.out.println("Length: 135 minutes");
System.out.println("Date: 20/01/08");
System.out.println("Number of tickets: "+tickets);
System.out.println("Price per ticket: $90.00");
System.out.println("Total: $"+fmt.format(totalPrice));
System.out.println("-----------------------------------------------");
System.out.println("<1>Confirm");
System.out.println("<2>Redo");
System.out.print("Please select your choice<1-2>:");
confirmRedo = input.nextInt();
switch(confirmRedo){
case 1 : System.out.println("\n************************************");
System.out.println("* Your ticket(s) is/are confirmed. *");
System.out.println("************************************");
confirmation[0]=""+title;
confirmation[1]=""+date;
confirmation[2]=""+tickets;
confirmation[3]=""+totalPrice;
break;
case 2 : showRedo();
break;
default: System.out.println("\nPlease select a valid choice.");
}
}
break;
default: System.out.println("\nPlease select a valid choice.");
}
break;
case 2 : showClassical();
break;
case 3 : showPopMusic();
break;
case 4 : break;
default: System.out.println("\nPlease select a valid choice.");
}
break;
case 2 : System.out.println("\nThank you for using this service.\n");
System.out.println("Concert Date Tickets Total(S$)");
System.out.println("----------- -------- --------- -----------");
System.out.println(""+confirmation[0]+" "+confirmation[1]+" "+confirmation[2]+" "+confirmation[3]);
break;
default: System.out.println("\nPlease select a valid choice.");
}
大家好..我的作业代码存在问题。
基本上我的任务是创建一个预订机票程序,在您选择了所需的选项并退出主菜单后,它会显示您确认预订机票的摘要。
我遇到问题的部分在于&lt; 2&gt; Redo选项,因为我在调用showRedo()之后没有得到任何值;
有人可以帮我吗?
答案 0 :(得分:1)
你的showRedo()
concertCategories = input.nextInt();
if(concertCategories==1){
如果它等于1,则仅处理输入。您没有处理输入2和3的情况。
您还应该考虑使用Java Switch语句而不是这个令人讨厌的if-else阶梯。
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html