Basic Programming Concepts Lab # 9 – Arrays Write a cinema reservation program to allow customer to reserve cinema seating. At the beginning of the program, ask the customer to input the name and display customize greeting message. Once the seat is reserved, it should be marked as ‘**’. If customer chooses a seat that has been reserved by other customer, display a message to inform customer and suggest the next available seat. Sample output:
Hi, what is your name? Amy
Welcome, Amy!
CINEMA 1 SEATING PLAN
00 01 02 03 04
05 06 07 08 09
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
Which seat do you want?
21
Would you like to make another booking?(Y or N)
If seat chosen has been reserved by others, advice next available seat.
Now for the code. The problem with the code is because I probably don't know how to change someone's "y" into a "true" for boolean. Why can't coding ever be easy?
import java.util.*;
public class cinema
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int booking;
String name;
int suggestion = 0;
boolean check1 = true;
String check2 = "_";
String check11 = "_";
//create array
final int ARRAY_LENGTH = 30;
int[] array = new int[ARRAY_LENGTH];
String[] seats = { "00", "01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10"
, "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" , "20" , "21"
, "22" , "23" , "24" , "25" , "26" , "27" , "28" , "29"};
System.out.println("Hi, what is your name?");
name = input.nextLine();
System.out.printf("Welcome,%s!\n",name);
System.out.println("*********************");
System.out.println("CINEMA 1 SEATING PLAN");
System.out.println("*********************");
do{
for(int a = 0; a < 30; a++ ){
System.out.printf("%s\t", seats[a]);
if (a % 5 == 4){
System.out.printf("\n");
}
}
System.out.println("Which seat do you want?");
booking = input.nextInt();
if(seats[booking] == "**"){
System.out.println("Sorry! Seat taken.");
for(int b = 0; b < 30; b++){
if(seats[booking + b] == "**"){
check2 = seats[booking + b];
}
else if(seats[booking - b] == "**"){
check2 = seats[booking - b];
}
else{
}
}//end for loop
System.out.printf("Suggest to take seat:%s\n", check2);
}//end if
seats[booking] = "**";
System.out.println("Would you like to make another booking?(Y or N)");
check11 = input.nextLine();
while(check11 == "y"||check11 == "n"){
if(check11 == "y"){
check1 = true;
System.out.print("a");
}
else if(check11 == "n"){
check1 = false;
System.out.print("b");
}
else{
System.out.println("Would you like to make another booking?(Y or N)");
check11 = input.nextLine();
}
}//end while
}while(check1);//outer while
}
//end main
}
Please don't flag it as a duplicate. The problem in it is different. I can't get the
"Would you like to make another booking?(Y or N)"
to work. When I meant I couldn't get it to work, I meant that the program wouldn't let me have the opportunity to enter y or n. The true problem is the check11 = input.nextLine();. Anyone can tell me what's wrong with it?
Also, the previous reference really didn't help. I didn't understand how it refers to my quetion.