Write a program to implement a theater seating chart. The seating chart should b
ID: 3880226 • Letter: W
Question
Write a program to implement a theater seating chart. The seating chart should be implemented as a two-dimensional array of ticket prices. Start with the array as follows with these prices in dollars. The array should be initialized in the code without any outside files. Allow the user to pick either a seat or a price or a display. Allow the user to enter s for seat, p for price, d for display, or q to quit. Mark sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price. If the user asks for a display of the available seats, show something like what is shown above so they can see what seat they want to choose. The seat in the bottom left corner could be chosen by entering 1 1 at the command line. Provide a main method that shows the implementation of your theater seating program. You should allow the user to keep entering selections until he or she wants to quit. Make sure all instructions are clear so the user knows what to do next. The class name should be SeatingChart.java. The program should not crash no matter what is entered.Explanation / Answer
import java.util.*;
public class SeatingChart{
public static void main(String args[]){
int[][] chart = { //intiatizing array
{10,10,10,10,10,10,10,10,10,10,10,10},
{10,10,10,10,10,10,10,10,10,10,10,10},
{10,10,20,20,20,20,20,20,20,20,10,10},
{10,10,20,20,20,20,20,20,20,20,10,10},
{20,20,30,30,40,40,40,40,30,30,20,20},
{20,20,30,30,40,40,40,40,30,30,20,20},
{20,30,30,40,40,40,40,40,40,30,30,20},
{20,30,30,40,40,40,40,40,40,30,30,20},
{30,30,40,40,50,50,50,50,40,40,30,30},
{30,40,50,50,50,50,50,50,50,50,40,30}
};
char choice='p'; //decalring variable to store required choice
Scanner in=new Scanner(System.in); //Scanner to take input
while(choice!='q'){ //loop until choice is quit
System.out.println("ENTER REQUIRED CHOICE");
System.out.println("p - To select price , d - to dislay chat, s - to select seat, q-quit");
choice=in.next().charAt(0); //taking character input
switch(choice){ //to switch between choices
case 'p': {
System.out.println("ENTER PRICE");
int price=in.nextInt(); //to take price input
int flag=0;
for(int i=0;i<10;i++){ //loop to find seat with required price
for(int j=0;j<12;j++)
if(chart[i][j]==price){ //if found
flag=1; //to find a seat is found or not
chart[i][j]=0; //assigning 0 so it can be found that seat is already alloted
System.out.println("YOU ARE ALLOTED SEAT NO : "+i+1+" "+j+1); //printing alloted seat no
break;
}
if(flag==1) //if seat alloted break
break;
}
if(flag==0) //if no such price found
System.out.println("ENTER VALID PRICE");
break;
}
case 'd': { //if user reqiures display
for(int i=9;i>=0;i--){
for(int j=11;j>=0;j--)
System.out.print(chart[i][j]+" "); //looping and printing whole array
System.out.println();
}
break;
}
case 's': {
System.out.println("ENTER SEAT POSITION X AND Y");
int x=in.nextInt(); //taking seat no input
int y=in.nextInt();
if(x>10||y>12||x<0||y<0){ //checking whether the seat no is valid
System.out.println("ENTER VALID SEAT NUMBER");
}
x--;y--; //as index starts from 0 the entered values are decremented
if(chart[x][y]==0)
System.out.println("SEAT NOT AVAILABLE");
else
System.out.println("SEAT AVAILABLE : price is"+ chart[x][y]);
break;
}
case 'q':{//chooses to quit
break;
}
default:{
System.out.println("ENTER VALID CHOICE");
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.