如何显示一个取决于用户想要的数组?

时间:2015-09-30 10:40:25

标签: java arrays jcreator

这是一种方法。

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:| ---------------&gt;”+住宿[SwitchOne]); < /强>

            }

    }else{
            continue;
        }

    }// End For Records 

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


}//IO
}//Body

我的计划是关于酒店信息和计费系统。

如果有2位客户想要办理登机手续并且他们选择不同的房间,当我检查客户的清单时,他们房间的输出是相同的。

我知道问题是

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

我该怎么做才能解决它?

请帮帮我。

1 个答案:

答案 0 :(得分: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]);
如果我错了,请通知我。