Java 如何根据用户需要显示阵列?

Java 如何根据用户需要显示阵列?,java,arrays,jcreator,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"};

这是第一种方法

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]);
我该怎么做才能把它修好

请帮帮我。

您正在使用SwitchOne了解所选的住宿。因此,如果记录数为2或更多,则最后一条记录将更改SwitchOne的值

因此,当您打印所有详细信息时,对于所有开关,一个将是相同的

为了避免这种情况,请为SelectedAccmadation[]创建一个新数组并从中获取它。 像这样

int[] Confirm = new int [100];
String[] selectedAccomadation = new String[100];
...
System.out.print("\n\nPlease Select Room Type: ");
selectedAccomadation[x] = br.readLine();
System.out.println("\nAccommodations: |---------------> " + selectedAccomadation[x]);
然后在循环中得到这样的结果

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

如果我错了,请通知我。

请仅将其减少到相关代码部分。这是否足够@欢迎来到SO。如果您:-缩进代码,人们会更愿意阅读。-遵循Java约定,使变量以小写字母开头。-多做些努力,以一种不需要人们努力解释你所说的数组的方式来解释?为了……住宿有什么价值?问题是如果记录是2,那么客户是2。。。那整句话是什么意思?。只要付出足够的努力,以上所有的一切都能被理解,这并不重要。你的工作就是尽可能减少帮助你所需的努力。这个怎么样?我详细说明了问题@但问题是他不知道该选哪个房间,因为它还没有显示出来。注册-->选择房间-->显示如果您对此程序有更好的想法,也许我可以使用它。