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

A theatre seating chart is implemented as a two-dimensional array of ticket pric

ID: 3708263 • Letter: A

Question

A theatre seating chart is implemented as a two-dimensional array of ticket prices, like this:

                AISLE

ROW      1           2             3             4             5             6             7             8             9              10

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

10           10           10           10           10           10           10           10           10           10           10

9             10           10           10           10           10           10           10           10           10           10

8             10           10           10           10           10           10           10           10           10           10

7             10           10           20           20           20           20           20           20           10           10

6             10           10           20           20           20           20           20           20           10           10

5            10           10           20           20           20           20           20           20           10           10

4             20           20           30           30           40           40           30           30           20           20

3             20           30           30           40           50           50           40           30           30           20

2            30           40           50           50           50           50           50           50           40           30

1            30           40           50           50           50           50           50           50           40           30

Write a program that prompts users to pick either a seat or a price. 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 starting at the front and working to the back of the theatre. Make sure you write your program using well defined functions.

Please do as follows :

You are to hand in:

Source code (well documented)

Input file (if used)

Sample tests for valid and invalid choices

Hierarchy Chart

User Guide

Explanation / Answer

package cinema;
import java.util.Scanner;


public class SeatingChart {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        int[][] seatsArr = {
            {30, 40, 50, 50, 50, 50, 50, 50, 50, 50, 40, 30},
            {30, 30, 40, 40, 50, 50, 50, 50, 40, 40, 30, 30},
            {20, 30, 30, 40, 40, 40, 40, 40, 40, 30, 30, 20},
            {20, 30, 30, 40, 40, 40, 40, 40, 40, 30, 30, 20},
            {20, 20, 30, 30, 40, 40, 40, 40, 30, 30, 20, 20},
            {20, 20, 30, 30, 40, 40, 40, 40, 30, 30, 20, 20},
            {10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 10, 10},
            {10, 10, 20, 20, 20, 20, 20, 20, 20, 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}};

        while (true) {
            System.out.println("MENU "
                    + " Press s - If you would like to pick a seat" + " "
                    + " Press p - if you would like to pick seat by price" + " "
                    + " Press d - If you would like a display of available seats" + " " + " q-Quit" + " " + "Choose an option");

            char option = scnr.next().charAt(0);
            switch (option) {
                case 's':
                case 'S':
                    System.out.print("Please enter row and column number ( EX: 1 2)--");
               int r = scnr.nextInt();
               int c = scnr.nextInt();
               //because array will start from (0,0) so 1,1 will be at 0,0
               if (seatsArr[r - 1][c - 1] != 0) {

                   System.out.printf("Seat   [%d %d] is available ! ", r, c);
                   // The Seat is found , so we will made the value of seatsArr[row][col]=0 , so
                   // that it can show status sold
                   seatsArr[r - 1][c - 1] = 0;
               }
                    break;

                case 'p':
                case 'P':
                    boolean foundSeat = false;

                    System.out.print(" please select a price ");
                    int price = scnr.nextInt();
                    for (int row = 0; row < seatsArr.length; row++) {
                        for (int col = 0; col < seatsArr[row].length; col++) {
                            if (seatsArr[row][col] == price) {
                                foundSeat = true;

                                System.out.printf("Seat   [%d %d] is available for that price! ", row+1, col+1);
                                //The Seat is found , so we will made the value of seatsArr[row][col]=0 , so that it can show status sold
                                seatsArr[row][col]=0;
                                //here you allocate first available seat at this price
                                break;
                            }
                        }
                      
                    if (foundSeat) {
                        break;
                    }
                    }
                    if (!foundSeat) {
                        System.out.println("We do not have any seat available at that price");
                    }

                    break;

                case 'd':
                case 'D':

                    for (int row = 0; row < seatsArr.length; row++) {
                        for (int col = 0; col < seatsArr[row].length; col++) {
                            System.out.print(seatsArr[row][col] + " ");
                        }
                        System.out.println();
                    }

                    break;

                case 'q':
                case 'Q':
                    System.exit(0);
                    break;
            }
        }

    }
}

output

MENU
Press s - If you would like to pick a seat
Press p - if you would like to pick seat by price
Press d - If you would like a display of available seats
q-Quit
Choose an option
p
please select a price 10
Seat   [7 1] is available for that price!
MENU
Press s - If you would like to pick a seat
Press p - if you would like to pick seat by price
Press d - If you would like a display of available seats
q-Quit
Choose an option
d
30 40 50 50 50 50 50 50 50 50 40 30
30 30 40 40 50 50 50 50 40 40 30 30
20 30 30 40 40 40 40 40 40 30 30 20
20 30 30 40 40 40 40 40 40 30 30 20
20 20 30 30 40 40 40 40 30 30 20 20
20 20 30 30 40 40 40 40 30 30 20 20
0 10 20 20 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 20 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
MENU
Press s - If you would like to pick a seat
Press p - if you would like to pick seat by price
Press d - If you would like a display of available seats
q-Quit
Choose an option

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