A theater seating chart is implemented as a two dimensional array of ticket pric
ID: 3752020 • Letter: A
Question
A theater seating chart is implemented as a two dimensional array of ticket prices like this: 10 10 20 20 10 10 20 20 20 20 30 30 20 30 30 40 You need to write a JAVA program that prompts users to pick a seat. Mark sold seats by changing the price to 0. When a user asks for a seat, make sure it is available. If it is not available prompt the user “This seat is not available”. First initialize seating matrix using initialization list as shown in the question. Your program should have 2 methods that: i) print the array public static void print_the_array(int myArray[][]) ii) sellSeatByNumber public static void sell_seat_by_num(int row, int col, int myArray[][])A theater seating chart is implemented as a two dimensional array of ticket prices like this: 10 10 20 20 10 10 20 20 20 20 30 30 20 30 30 40 You need to write a JAVA program that prompts users to pick a seat. Mark sold seats by changing the price to 0. When a user asks for a seat, make sure it is available. If it is not available prompt the user “This seat is not available”. First initialize seating matrix using initialization list as shown in the question. Your program should have 2 methods that: i) print the array public static void print_the_array(int myArray[][]) ii) sellSeatByNumber public static void sell_seat_by_num(int row, int col, int myArray[][])
A theater seating chart is implemented as a two dimensional array of ticket prices like this: 10 10 20 20 10 10 20 20 20 20 30 30 20 30 30 40 You need to write a JAVA program that prompts users to pick a seat. Mark sold seats by changing the price to 0. When a user asks for a seat, make sure it is available. If it is not available prompt the user “This seat is not available”. First initialize seating matrix using initialization list as shown in the question. Your program should have 2 methods that: i) print the array public static void print_the_array(int myArray[][]) ii) sellSeatByNumber public static void sell_seat_by_num(int row, int col, int myArray[][])
Explanation / Answer
import java.util.*;
import java.text.*;
class SeatBooking{
public static void print_the_array(int myArray[][])
{
for (int[] x:myArray)
{
for (int y:x)
{
System.out.print(y+" ");
}
System.out.println();
}
}
public static void sell_seat_by_num(int row, int col, int myArray[][])
{
if(myArray[row][col]!=0)
{
myArray[row][col]=0;
System.out.println("Your Seat is booked! Your Seat number is :"+(row+1)+(col+1));
}
else{
System.out.println("This seat is not available");
}
}
public static void main(String args[])
{
int arr[][]={
{10,10,20,20},
{10,10,20,20},
{20,20,30,30},
{20,30,30,40}
};
while(true){
System.out.println("Want to book a Seat? (Y/N)");
Scanner sc=new Scanner(System.in);
char c=sc.nextLine().charAt(0);
if(c=='Y'||c=='y'){
print_the_array(arr);
System.out.println("Enter the row and column number to pick a seat :");
System.out.println("Enter the row: ");
int row=sc.nextInt();
System.out.println("Enter the column: ");
int col=sc.nextInt();
sell_seat_by_num(row-1,col-1,arr);
}
else
{
break;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.