Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Does anyone has the code in java for this problem?? A theater seating chart is i

ID: 3569720 • Letter: D

Question

Does anyone has the code in java for this problem??

A theater seating chart is implemented as a two-dimensional array of ticket prices like presented below. Write a program that prompts the users to pick either a seat or a price. Mark sold seats by changing the price to zero. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price. Verify that the price is among those offered by the theater.

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 10 10 10 10
10 10 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 10 10
20 20 30 30 40 40 30 30 20 20
20 30 30 40 50 50 40 30 30 20
30 40 50 50 50 50 50 50 40 30

Explanation / Answer

Program Code:

// TheaterReservation.java

import java.util.*;

public class TheaterReservation

{

     static Scanner in = new Scanner(System.in);

     static int[][] seatingtable;

     public static void main(String[] args)

     {

          seatingtable = new int[][] {

                   { 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, 10, 10, 10, 10 },

                   { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },

                   { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },

                   { 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },

                   { 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },

                   { 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },

                   { 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 },

          };

          //display the information

          System.out.println("Welcome to the Box Office Program.");              

          System.out.println("Please note that seats are arranged such that");

          System.out.println("row 1, column 1, is the bottom front row.");

          System.out.println("Also, a zero denotes the seat is already reserved.");

          displaySeats(seatingtable);

          char reply = 'Y';

          while ((reply == 'Y') || (reply == 'y'))

          {

              System.out.print("Pick by Seat <s>, Price <p>, or Quit <q>: ");

              char choice = in.next().charAt(0);

              switch (choice)

              {

              case'S':case's':

              {

                   reserveSeatByNumber(seatingtable);

                   break;

              }

              case'P':case'p':

              {

                   reserveSeatByPrice(seatingtable);

                   break;

              }

              case'Q':case'q':

              {

                   System.out.print("Thank you, come again!");

                   System.exit(0);

              }

              default:

              {

                   System.out.println("Error: Invalid choice.");

              }

              }

              System.out.print("Would you like to reserve another seat (Y/N)?: ");

              reply = in.next().charAt(0);

          }

          System.out.print("Thank you, visit again!");

     }

     //displaySeats will displays the reserved seats

     public static void displaySeats(int seatsReservation[][])

     {

          for(int i=0; i<seatsReservation.length; i++)

          {

              for(int j=0; j<seatsReservation[i].length; j++)

              {

                   if (j>0)

                        System.out.print(" ");

                   System.out.print(seatsReservation[i][j]);

              }

              System.out.println();

          }

     }

     //reserveSeatByPrice method to reserve the seats by Price

     public static void reserveSeatByPrice(int seatsReservation[][])

     {

          System.out.print("Please enter a price for the seat you would like: ");

          int price = in.nextInt();

          // boolean found = false;

          out: for (int i=0;i<9;i++)

              for (int j=0;j<10;j++)

                   if (seatsReservation[i][j]==price)

                   {

                        seatsReservation[i][j]=0;

                        break out;

                   } // Notice this change

                   displaySeats(seatsReservation);

     }

     //reserveSeatByNumber to reserve the seats by Number

     public static void reserveSeatByNumber(int seatsReservation[][])

     {

          System.out.println("Enter a row, followed by seat number.");

          System.out.print("Which row seat would you like to reserve?:");

          int row = in.nextInt();

          row = Math.abs(row-9);

          System.out.print("Which seat number would you like to reserve in the row:");

          int col = in.nextInt();

          col -= 1;

          if (seatsReservation[row][col]!=0)

          {

              seatsReservation[row][col] = 0;

              displaySeats(seatsReservation);

              System.out.println("Your seat has been reserved and reflected with a 0 on the chart now.");

          }

          else

          {

              System.out.println("Sorry, that seat is already reserved.");

          }

     }

}

-------------------------------------------------------------------------------------------------------------------------

Sample output:

Welcome to the Box Office Program.

Please note that seats are arranged such that

row 1, column 1, is the bottom front row.

Also, a zero denotes the seat is already reserved.

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   10   10   10   10

10   10   20   20   20   20   20   20   10   10

10   10   20   20   20   20   20   20   10   10

10   10   20   20   20   20   20   20   10   10

20   20   30   30   40   40   30   30   20   20

20   30   30   40   50   50   40   30   30   20

30   40   50   50   50   50   50   50   40   30

Pick by Seat <s>, Price <p>, or Quit <q>: s

Enter a row, followed by seat number.

Which row seat would you like to reserve?:5

Which seat number would you like to reserve in the row:5

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   10   10   10   10

10   10   20   20   20   20   20   20   10   10

10   10   20   20   0    20   20   20   10   10

10   10   20   20   20   20   20   20   10   10

20   20   30   30   40   40   30   30   20   20

20   30   30   40   50   50   40   30   30   20

30   40   50   50   50   50   50   50   40   30

Your seat has been reserved and reflected with a 0 on the chart now.

Would you like to reserve another seat (Y/N)?: y

Pick by Seat <s>, Price <p>, or Quit <q>: s

Enter a row, followed by seat number.

Which row seat would you like to reserve?:5

Which seat number would you like to reserve in the row:6

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   10   10   10   10

10   10   20   20   20   20   20   20   10   10

10   10   20   20   0    0    20   20   10   10

10   10   20   20   20   20   20   20   10   10

20   20   30   30   40   40   30   30   20   20

20   30   30   40   50   50   40   30   30   20

30   40   50   50   50   50   50   50   40   30

Your seat has been reserved and reflected with a 0 on the chart now.

Would you like to reserve another seat (Y/N)?: y

Pick by Seat <s>, Price <p>, or Quit <q>: s

Enter a row, followed by seat number.

Which row seat would you like to reserve?:6

Which seat number would you like to reserve in the row:5

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   10   10   10   10

10   10   20   20   0    20   20   20   10   10

10   10   20   20   0    0    20   20   10   10

10   10   20   20   20   20   20   20   10   10

20   20   30   30   40   40   30   30   20   20

20   30   30   40   50   50   40   30   30   20

30   40   50   50   50   50   50   50   40   30

Your seat has been reserved and reflected with a 0 on the chart now.

Would you like to reserve another seat (Y/N)?: y

Pick by Seat <s>, Price <p>, or Quit <q>: p

Please enter a price for the seat you would like: 20

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   10   10   10   10

10   10   0    20   0    20   20   20   10   10

10   10   20   20   0    0    20   20   10   10

10   10   20   20   20   20   20   20   10   10

20   20   30   30   40   40   30   30   20   20

20   30   30   40   50   50   40   30   30   20

30   40   50   50   50   50   50   50   40   30

Would you like to reserve another seat (Y/N)?: y

Pick by Seat <s>, Price <p>, or Quit <q>: p

Please enter a price for the seat you would like: 20

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   10   10   10   10

10   10   0    0    0    20   20   20   10   10

10   10   20   20   0    0    20   20   10   10

10   10   20   20   20   20   20   20   10   10

20   20   30   30   40   40   30   30   20   20

20   30   30   40   50   50   40   30   30   20

30   40   50   50   50   50   50   50   40   30

Would you like to reserve another seat (Y/N)?: n

Thank you, visit again!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote