2015-09-30 13 views
0

這是1種方法。如何顯示將取決於用戶想要的數組?

public static void main(String[] Ropher)throws IOException{ 
    BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); 

    String[] Accommodation = {"", "Standard Room", "Double Room", "Matrimonial Room", "Triple Room"}; // Accommodation 
    int SwitchOne, SwitchTwo; 
    int Option;//Options 

    /*----------------------------------------------------------------- 
    * Costumer's Information 
    -----------------------------------------------------------------*/ 
    do{//Start Of First Loop - Customer's Info 
    System.out.print("\nEnter Number Of Records : "); 
    int Records = Integer.parseInt(br.readLine()); 
    String [][] Fullname = new String [Records][100]; 
    int [] Night = new int[100]; 
    int [] Guest = new int[100]; 
    int[] Confirm = new int [100]; 
    for (int x = 0; x < Records; x++){// Start For Records 

    System.out.print("\nConfimation Number: "); 
    Confirm[x] = Integer.parseInt(br.readLine()); 
    System.out.print("\nFirst Name: "); 
    Fullname[x][0] = br.readLine(); 
    System.out.print("Last Name: "); 
    Fullname[x][1] = br.readLine(); 
    System.out.print("Guest: "); 
    Guest[x] = Integer.parseInt(br.readLine()); 
    System.out.print("Night: "); 
    Night[x] = Integer.parseInt(br.readLine()); 
    System.out.println(); 

    do{// Start Of Second - Main Menu 

     System.out.print("\n        ||Main Menu||\n\n"); 
     System.out.print("|=====================================================================|"); 
     System.out.print("\n ************************  Bed Types  ************************\n"); 
     System.out.print("|=====================================================================|\n\n"); 
     System.out.print("1. Standard..............................................P500.00\n"); 
     System.out.print("2. Double................................................P800.00\n"); 
     System.out.print("3. Matrimonial...........................................P1,240.00\n"); 
     System.out.print("4. Triple................................................P1,500.00 \n"); 
     System.out.print("5. Exit\n"); 
     System.out.println("\n (WIfi, air conditioned room, LED TV, FREE BREAKFAST)"); 
     System.out.println("\t *Except Standard rooms and Double rooms");  

     System.out.print("\n\nPlease Select Room Type: "); 
     SwitchOne = Integer.parseInt(br.readLine()); 

     //Start of Switch for SwitchOne - First Switch 


    if ((x + 1 - Records) == 0){ 

    System.out.print("\n\nList Of Customers:"); 

    for (x = 0; x < Records; x++){ 

     System.out.print("\n|---------------------------------------------------------------------|\n"); 
     System.out.print("\n\nConfirmation Number:  |---------------> " + Confirm[x]); 
     System.out.print("\nGuest Name:     |---------------> " + Fullname [x][0] + " " + Fullname [x][1]); 
     System.out.print("\nNumber Of Guest:   |---------------> " + Guest [x]); 
     System.out.print("\nNumber Of Nights:   |---------------> " + Night[x]); 

這只是一個選項,我只是不知道什麼價值放在住宿。

System.out.println(「\ nAccommodations:| --------------->」+ Accommodation [SwitchOne]);

  } 

    }else{ 
      continue; 
     } 

    }// End For Records 

    }while (First);//End Of First Loop - Customer's Info 


}//IO 
}//Body 

我的計劃是所有關於酒店信息和計費系統。

如果有2位顧客想要辦理登機手續並且他們選擇不同的房間,並且當我檢查客戶名單時,他們房間的輸出是相同的。

而且我知道,這個問題是

System.out.println("\nAccommodations:    |---------------> " + Accommodation[SwitchOne]); 

我會做什麼,以固定的呢?

請幫我解決這個問題。

+0

請將其降低到相關的代碼部分 –

+0

這夠了嗎? @Parker_Halo – Geoddie

+1

歡迎來到SO。如果你有以下情況,人們會更願意閱讀: - 縮進代碼。 - 遵循Java約定,並使變量以小寫字母開頭。 - 做一些更努力的解釋,不需要人們努力去解釋你的意思(_「叫一個陣列」_?_「爲住房提供什麼價值」_以便...? _「問題是如果記錄是2客戶是2 ...」_那整個句子是什麼意思?)。 沒有關係,只要有足夠的努力,上述所有內容都可以被理解。減少幫助你所需的努力是你的工作。 – SantiBailors

回答

0

您正在使用SwitchOne來了解所選的準確度。所以如果記錄是2或更多,則最後一條記錄將改變SwitchOne的值。

所以當你打印所有的細節時,對於所有的SwitchOne將會是一樣的。

避免爲selectedAccomadation []創建一個新的數組並從那裏獲取它。 這樣

int[] Confirm = new int [100]; 
String[] selectedAccomadation = new String[100]; 
... 
System.out.print("\n\nPlease Select Room Type: "); 
selectedAccomadation[x] = br.readLine(); 

而且在for循環得到這樣

System.out.println("\nAccommodations: |---------------> " + selectedAccomadation[x]); 

請通知我,如果我錯了。

+0

但事情是他不知道有什麼空間可以挑選,因爲它還沒有顯示。 註冊---->選擇房間---->顯示 如果你對這個程序有更好的主意,也許我可以使用它。 – Geoddie

相關問題