Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 阵列列表循环_Java_Loops_Arraylist - Fatal编程技术网

Java 阵列列表循环

Java 阵列列表循环,java,loops,arraylist,Java,Loops,Arraylist,在预订菜单中,我有3个选项:a、b和c。 选项“a”-选择房间类型。5种不同的房间类型可供选择。 选项“b”-为每个房间选择附加组件。可以选择每个附加组件以增加成本。 选项“c”-从预订页面返回主页 我的程序需要显示5种不同类型的房间。此时,客户只允许选择选项“a”、“b”或“c” 如果客户在选择房间时输入了无效的数字(不包括1到5),系统应给出错误消息并提示用户再次输入。用户输入了他/她想要的房间类型后,他们可以继续输入每种类型房间的数量。 选择房间类型后,系统将提示您为每个房间类型选择附加组

在预订菜单中,我有3个选项:a、b和c。 选项“a”-选择房间类型。5种不同的房间类型可供选择。 选项“b”-为每个房间选择附加组件。可以选择每个附加组件以增加成本。 选项“c”-从预订页面返回主页

我的程序需要显示5种不同类型的房间。此时,客户只允许选择选项“a”、“b”或“c”

如果客户在选择房间时输入了无效的数字(不包括1到5),系统应给出错误消息并提示用户再次输入。用户输入了他/她想要的房间类型后,他们可以继续输入每种类型房间的数量。 选择房间类型后,系统将提示您为每个房间类型选择附加组件

这是我下面的代码。当用户选择选项“b”时,我无法从选项“a”获取存储在integer arraylist中的加载项数

我初始化了2个arraylist,但不确定它们是否正确。第一个arraylist用于存储roomtype和date字符串。第二个arraylist是integer,它存储房间价格、所需房间数、附加组件数、夜数、用户选择的附加组件选项以及附加组件的数量

我对编码很陌生,所以需要帮助

import java.util.*;
import java.io.*;

public class RoomSelection {

    public RoomSelection() throws InputMismatchException {

        String choiceStr;//initialize choiceStr which is use for reading lines from scanner input
        char choiceChar;//initialize choiceStr which is use for reading character from scanner input
        int choice;//initialize choiceStr which is use for reading integer from scanner input
        String datee;
        String[] roomType = {"Single Room", "Double Room", "Deluxe Room", "Junior Room", "Suite"}; //Initialize a array for room type
        Integer[] priceRoom = {160, 200, 280, 380, 500}; //Initialize a array for room prices
        Integer[] priceAdd = {25, 60, 70, 100}; //Initialize a array for add-on prices

        ArrayList<String> roomAndDate = new ArrayList<String>();
        ArrayList<Integer> all = new ArrayList<Integer>();
        Scanner input = new Scanner(System.in); //Initialize a scanner input

        System.out.println("Room Selection");
        System.out.println("==============\n");
        System.out.println("[a] Room Type");
        System.out.println("[b] Add-Ons");
        System.out.println("[c] Main Menu");
        System.out.println("Type 'a' to select Room Type and state the desire quantity for each type.");
        System.out.println("Type 'b' to select the Add-Ons.");
        System.out.println("Type 'c' to exit from  the Booking Menu.");
        System.out.println("Please enter your option (a, b or c): ");

        choiceStr = input.nextLine();
        choiceChar = choiceStr.charAt(0);
        while (true) {

            switch (choiceChar) {
                case 'a':
                    System.out.println("Room Type");
                    System.out.println("=====================================================");
                    System.out.println("(1) Single Room (1 person) - Price: S$160");
                    System.out.println("(2) Double Room (2 persons) - Price: S$200");
                    System.out.println("(3) Deluxe Room (2 persons) - Price: S$280");
                    System.out.println("(4) Junior Suite (2 persons) - Price: S$380");
                    System.out.println("(5) Suite (2 persons) - Price: S$500\n");
                    System.out.println("Enter Room types (Enter '1' to '5')");
                    choice = input.nextInt();
                    while (choice > 5) {
                        if (choice > 5) {
                            System.out.println("Please enter number between '1' to '5'!");
                            choice = input.nextInt();
                        }
                    }

                    String roomTypess = roomType[choice - 1];
                    roomAndDate.add(roomTypess);
                    int storePricee = priceRoom[choice - 1];
                    all.add(storePricee);

                    System.out.println("Number of rooms required (maximum 10): ");
                    choice = input.nextInt();
                    while (choice > 10) {
                        if (choice > 10) {
                            System.out.println("Please enter again!");
                            choice = input.nextInt();
                        }
                    }
                    all.add(choice);

                    for (int i = 0; i < choice; i++) {
                        System.out.println("Enter the date of checked-in (dd/mm/yy) for " + roomAndDate.get(0) + " " + (i + 1));
                        choiceStr = input.nextLine();
                        choiceStr = input.nextLine();
                        roomAndDate.add(choiceStr);
                        System.out.println(roomAndDate);
                        System.out.println("Enter number of Add-on for " + roomAndDate.get(0) + " " + (i + 1) + ": ");
                        choice = input.nextInt();
                        while (choice > 4) {
                            if (choice > 4) {
                                System.out.println("Please enter again! Choose only option 1 to 4");
                                choice = input.nextInt();
                            }
                        }
                        all.add(choice);
                        System.out.println("Number of night(s) required (maximum 30) for " + roomAndDate.get(0) + " " + (i + 1) + ": ");
                        choice = input.nextInt();
                        while (choice > 30) {
                            if (choice > 30) {
                                System.out.println("Please enter again! Maximum is 30 days!");
                                choice = input.nextInt();
                            }
                        }
                        all.add(choice);


                    }

                    new RoomSelection();
                    break;
                case 'b':
                    System.out.println("Add-Ons");
                    System.out.println("=====================================================");
                    System.out.println("(1) Breakfast voucher (1 person) per day - Price: S$25");
                    System.out.println("(2) Spa voucher (1 person) - Price: S$60");
                    System.out.println("(3) Half Day Tour voucher (1 person) - Price: S$70");
                    System.out.println("(4) Full Day Tour voucher (1 person) - Price: $100\n");



                    for (int i = 0; i < (Integer) all.get(3); i++) {

                        System.out.println("Enter Add-On option");
                        choice = input.nextInt();
                        while (choice > 4) {
                            if (choice > 4) {
                                System.out.println("Please enter again! Choose only option 1 to 4");
                                choice = input.nextInt();
                            }
                        }
                        all.add(choice);
                        System.out.println("Enter quantity required for Add-On option " + (i + 1) + ": ");
                        choice = input.nextInt();
                        all.add(choice);
                    }


                    break;
                case 'c':
                    new MainPage1();
                    break;
                default:
                    continue;
            }
        }
    }
}
import java.util.*;
导入java.io.*;
公共教室选择{
public RoomSelection()抛出InputMismatchException{
String choiceStr;//初始化用于从扫描仪输入读取行的choiceStr
char choiceChar;//初始化用于从扫描仪输入读取字符的choiceStr
int choice;//初始化choiceStr,用于从扫描仪输入读取整数
字符串日期;
String[]roomType={“单人房”、“双人房”、“豪华房”、“初级房”、“套房”};//初始化房间类型的数组
整数[]priceRoom={160200280380500};//初始化房间价格数组
整数[]priceAdd={25,60,70,100};//初始化附加价格的数组
ArrayList roomAndDate=新建ArrayList();
ArrayList all=新的ArrayList();
扫描仪输入=新扫描仪(System.in);//初始化扫描仪输入
System.out.println(“房间选择”);
System.out.println(“============================\n”);
System.out.println(“[a]房间类型”);
System.out.println(“[b]附加组件”);
System.out.println(“[c]主菜单”);
System.out.println(“键入'a'以选择房间类型并说明每种类型的所需数量”);
System.out.println(“键入'b'以选择附加组件”);
System.out.println(“键入'c'退出预订菜单”);
System.out.println(“请输入您的选项(a、b或c):”;
choiceStr=input.nextLine();
choiceChar=choiceStr.charAt(0);
while(true){
开关(choiceChar){
案例“a”:
System.out.println(“房间类型”);
System.out.println(“=====================================================================================”);
系统输出打印号(“(1)单人房(1人)-价格:160新元”);
系统输出打印号(“(2)双人间(2人)-价格:200新元”);
系统输出打印号(“(3)豪华房(2人)-价格:280新元”);
系统输出打印号(“(4)初级套房(2人)-价格:380新元”);
System.out.println(“(5)套(2人)-价格:S$500\n”);
System.out.println(“输入房间类型(输入'1'到'5')”;
choice=input.nextInt();
while(选项>5){
如果(选项>5){
System.out.println(“请输入介于'1'到'5'之间的数字!”;
choice=input.nextInt();
}
}
字符串roomTypess=roomType[choice-1];
roomAndDate.add(roomTypess);
int storeprice=priceRoom[choice-1];
全部。添加(StorePrice);
System.out.println(“所需房间数(最多10间):”;
choice=input.nextInt();
while(选项>10){
如果(选项>10){
System.out.println(“请再次输入!”);
choice=input.nextInt();
}
}
全部。添加(选择);
for(int i=0;i4){
如果(选项>4){
System.out.println(“请再次输入!仅选择选项1到4”);
choice=input.nextInt();
}
}
全部。添加(选择);
System.out.println(“对于“+roomAndDate.get(0)++”+(i+1)+“:”,需要的夜数(最多30);
choice=input.nextInt();
while(选项>30){
如果(选项>30){
System.out.println(“请重新输入!最多30天!”);
choice=input.nextInt();
}
}