Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList looping
    primarykey
    data
    text
    <p>In Booking menu, i have main with 3 options:a,b and c. Option 'a' - selection of room types. 5 different room types to choose from. Option 'b'- selection of add-ons for each room.Each add-on can be selected for additional cost. Option 'c' - return from make booking page to main page</p> <p>My program needs to display 5 different types of room. At this point customer is only allowed to select option 'a', 'b' or 'c'.</p> <p>If customer enters and invalid number which is not 1 to 5 inclusive when selecting room ,system should give error message and prompt user to enter again.Once the user entered the type of room he/she wants, they can proceed to enter quantity for each type of room. After the selection of room type, the system will prompt you to select add-ons for each room type.</p> <p>This is my code below.I cant to get my number of add-ons i stored in the integer arraylist from option 'a' when the user selection option 'b'.</p> <p>I initialized 2 arraylist but im not sure whether they are correct. The first arraylist is to store strings which is roomtype and date. The second arraylist is integer, which stores room price,number of room require, number of add-ons,number of nights,add-on option the user selects and quantity of the add-on.</p> <p>I'm quite new to coding so need help on it.</p> <pre><code>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&lt;String&gt; roomAndDate = new ArrayList&lt;String&gt;(); ArrayList&lt;Integer&gt; all = new ArrayList&lt;Integer&gt;(); 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 &gt; 5) { if (choice &gt; 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 &gt; 10) { if (choice &gt; 10) { System.out.println("Please enter again!"); choice = input.nextInt(); } } all.add(choice); for (int i = 0; i &lt; 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 &gt; 4) { if (choice &gt; 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 &gt; 30) { if (choice &gt; 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 &lt; (Integer) all.get(3); i++) { System.out.println("Enter Add-On option"); choice = input.nextInt(); while (choice &gt; 4) { if (choice &gt; 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; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload