2013-12-20 23 views
-3
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."); 
      } 

嗨,夥計們..我的代碼有問題,我的任務。在調用方法後,我的數組列表爲空值

基本上我的任務是創造出您選擇您想要的選項後的預訂票程序,並退出主菜單,它會告訴你你的確認訂好機票的總結。

在那裏我有一個問題就出在< 2>重做,因爲我沒有要求showRedo後得到任何值()選項的一部分;

任何人都可以幫助我嗎?

+0

「我沒有得到任何價值」 - 你是什麼意思? –

+2

嘗試將代碼減少到最低摘錄出這個問題,沒有人想讀那麼多的代碼,並找出適合你什麼在 – 2013-12-20 14:33:21

+0

去你能更清楚地解釋你的問題?具體來說,「調用sh​​owRedo()後我沒有得到任何價值」是什麼意思?沒有獲得價值在哪裏?你期望看到什麼,它與你看到的有什麼不同? – JVMATL

回答

1

你showRedo()

concertCategories = input.nextInt(); 

    if(concertCategories==1){ 

只處理輸入,如果它等於1。你不必處理輸入2和3

你也應該考慮使用Java的情況下,切換語句,而不是這個大的討厭的if-else梯子。

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

+0

如果陳述只會有1-3個選擇,如果未來可能會有更多的項目,交換機是要走的路。恕我直言,這是問題的嵌套水平。我會解決它有一個數據庫的顯示信息和子方法來處理每個子選擇。它會幹掉很多代碼。 – yonitdm

+0

@yonitdm有與此構成方式問題/批號/,但我敢肯定,這是一個更介紹類,Java和我不認爲它有助於壓倒他在這一點上。 – Jazzepi

+0

我在回答之前稱重(因此作爲評論而不是答案)。初學者使用DRY代碼的好處是,它使得跟蹤和調試比文本牆更容易。如果沒有其他更改,更改爲開關將不會改進代碼。啓動EM年輕的我說:) – yonitdm

相關問題