Question

P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this:...

P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this:

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

(Note that there are 9 rows, and 10 columns).

Program Function

We will write a program that allows a user to pick a seat to purchase.  The program will:

  1. Display the seating chart with the prices as a 9x10 table.  Rows are numbered 1 thru 9 from the stage to the back and, in each row, seats are numbered 1 thru 10 from the left as seen from the stage facing the audience.
  2. Prompt the user to enter a value indicating if they want to pick a seat by location (“1”) or by price (“2”) or have the system pick the best seat available (“3”).  The user may also enter a “0” to quit the program.  If they want to pick by location, prompt for row and seat number. If by price, prompt for price (10,20,30,40, or 50).
  3. When a user specifies a seat by location or price, make sure it is available.  If not, tell the user it is not available and give them another chance.  If all seats are sold, tell the user and don’t give them another chance.  
  4. If the seat is available mark it sold by changing the price to 0 in the table and tell the user:
    1. The price if the selection was by location; or
    2. The location if the selection was by price; or
    3. The price and the location if the selection was best available.
  5. After each seat is sold, re-display the current seating chart (showing the available seats).
  6. End the program when all seats are sold or when the user enters  “0” to quit, whichever comes first.

Program Design

You will have two classes in this program:

  1. The TheaterSeatTesterclass that accepts seat requests from the user and services those requests with the appropriate method calls.  It runs until all seats are sold or the user quits.
  2. The TheaterSeatSellerclass that displays the seating chart on request, looks for available seats on request, and marks requested seats sold.

TheaterSeatTester Class

  1. Declare and initialize a test array with the seat price values shown in the table above and pass that array to a newly created TheaterSeatSeller object as a constructor parameter.  (Seat prices may vary depending on what who/what the entertainment is and what day/time the shows are).
  2. Declare and initialize a totalSold counter to count the seats sold.  The definition of no more seats available will be when totalSold equals the total number of seats in the theater.
  3. Declare and initialize any additional variables necessary to perform the functions below.
  4. Run (loop) to repeatedly find and mark sold seats in the theater until all are sold or the user enters “0” to quit.
  5. Display the current seating chart by calling theprintSeats method.
  6. Prompt the user for input as described in the program function above.  
  7. Edit the input received for validity and repeat the prompt until a valid response is received.
  8. If the input is “0” display a message (e.g. “Goodbye”) and quit the program.
  9. If the input is “1” invoke the getByLoc method, passing the row and seat requested.
  10. If the input is “2” invoke the getByPrice method passing the price requested.
  11. If the input is “3” invoke the getBest method.
  12. For every seat successfully sold (a good return from any of the get methods), increment the totalSold counter and use it to stop the program when all seats are sold.

TheaterSeatSeller Class

  1. Declare a 2D array named seats to be a matrix representing the rows and seats in the theater. This is the instance variable for the class.  The array will be initialized in the class Constructor by copying the test array passed in the constructor parameter to seats. This will be a true copy, not a copy by reference.
  2. Code a constructor for the class that will accept an array reference of test values for the seat prices and use it to initialize seats.  
  3. Code a printSeatsmethod to display the formatted seating chart on request.
  4. Code a getByLocmethod.  It accepts two integer parameters for row and seat and returns a Boolean response indicating success or failure (seat was available or not). Use the row and seat to locate the corresponding price element in the array and determine availability (not available if 0).  If available, display a message that the seat at that location (name the location) will be reserved and the price.  Mark the seat sold by changing price to 0.
  5. Code a getByPricemethod.  It accepts a price (an integer, as prices will always be expressed as whole dollars), and returns a Boolean response indicating success or failure (seat was available or not).  Use price to locate the first available seat in a row at that price closest to the front (stage).  If available, display a message that the seat at that price (name the price) will be reserved and the location (row and seat number).  Mark the seat sold by changing the price to 0.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi

Here are the two classes you will be needing, the program is working fine.checkout the sample output at the end.

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

public class TheaterSeatSeller {

    private static int[][] seats = {
            {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},

    };

    public TheaterSeatSeller() {

    }

    public void printSeats() {
        for (int row = 0; row <= 8; row++) {
            for (int col = 0; col <= 9; col++) {
                System.out.printf("%4d", seats[row][col]);
            }
            System.out.println();
        }

    }

    public boolean getByLoc(int row, int col) {
        if (1 <= row && row <= 10 && 1 <= col && col <= 11) {
            if (seats[row - 1][col - 1] != 0) {
                System.out.println("Seat Price: $" + seats[row - 1][col - 1]);
                System.out.println("Seat Booked successfully!");
                seats[row - 1][col - 1] = 0;
                return true;
            } else {
                System.out.println("Seat already sold out");
                return false;
            }
        } else {
            System.out.println("Enter valid row and col");
            return false;
        }
    }

    public boolean getByPrice(int price) {

        for (int row = 8; row >= 0; row--) {
            for (int col = 9; col >= 0; col--) {
                if (seats[row][col] == price && seats[row][col] != 0) {
                    System.out.println("Seat available at row: " + (row + 1)
                            + " col: " + (col + 1));
                    System.out.println("Seat Booked successfully");
                    seats[row][col] = 0;
                    return true;
                }
            }
        }
        System.out.println("No seat available at this price.");
        return false;
    }

    public boolean allSeatsSold() {
        int total = 0;

        for (int row = 0; row <= 8; row++) {
            for (int col = 0; col <= 9; col++) {
                total += seats[row][col];
            }
        }
        return total == 0;
    }

    public boolean getBest() {
        for (int row = 8; row >= 0; row--) {
            for (int col = 9; col >= 0; col--) {
                if (seats[row][col] != 0) {
                    System.out.println("Seat available at row: " + (row + 1)
                            + " col: " + (col + 1));
                    System.out.println("Seat Booked successfully");
                    seats[row][col] = 0;
                    return true;
                }
            }
        }
        System.out.println("No more seats available");
        return false;

    }
}

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

import java.util.Scanner;

public class TheaterSeatTester {

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

    public static void main(String[] args) {

        TheaterSeatSeller theater = new TheaterSeatSeller();
        while (!theater.allSeatsSold()) {

            System.out.println("[1] - Type to book seat by location");
            System.out.println("[2] - Type to book seat by price");
            System.out.println("[3] - Type to book seat by best");
            System.out.println("[0] - Type to exit");

            int choice = scanner.nextInt();
            if (choice == 0) {
                System.out.println("Goodbye");
                break;
            } else if (choice == 1) {
                System.out.print("Enter row: ");
                int row = scanner.nextInt();
                System.out.println("Enter col: ");
                int col = scanner.nextInt();
                theater.getByLoc(row, col);

            } else if (choice == 2) {
                System.out.print("Enter price - (10,20,30,40, or 50) ");
                int price = scanner.nextInt();
                theater.getByPrice(price);

            } else if (choice == 3) {
                theater.getBest();
            }
            theater.printSeats();
        }
    }

}

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

囚Chegg [C:\Users User IdeaProjectsi Chegg]--NsrcTheaterSeatTesterjava [Chegg]-IntelülDEA Eile Edit Yiew Navigate Code Analyze

thanks a lot!

Add a comment
Know the answer?
Add Answer to:
P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A theater seating chart is implemented as a two-dimensional array of ticket prices like presented below....

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

  • Write pseudocode for a program where the seating map for a particular performance at a theater...

    Write pseudocode for a program where the seating map for a particular performance at a theater contains 70 rows of 100 seats each. Using an array where applicable, develop the pseudeocode for a program that allows a user to continuously enter each household size and then a) Allows a user to continuously enter a row number and seat number until they enter an appropriate sentinel value for the row number in order to stop entering input. Each time the user...

  • I need help fixing this code and adding a loop please. Here is the original problem: #include <iostream> using namespace std; //function to print seating chart void printSeatingChart(int **cha...

    I need help fixing this code and adding a loop please. Here is the original problem: #include <iostream> using namespace std; //function to print seating chart void printSeatingChart(int **chart) {    int i, j;    cout << "\nROW\t";    for (i = 1; i <= 10; i++)    {        cout << i << "\t";    }    cout << "\n-----------------------------------------------------------------------------------\n";    for (i = 8; i >= 0; i--)    {        cout << "\n" << i + 1 << "\t";        for (j = 0; j < 10; j++)       ...

  • Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your...

    Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your program should display the following menu of alternatives: Please type 1 for "section A, $50/ticket" type 2 for "section B, $70/ticket", and type 3 for "section C, $80/ticket".  If the user types 1, then your program should assign a seat in the A section (seats 1–50). If the user types 2, then your program should assign a seat in the B section (seats 51–100). If...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • Your assignment is to design a TicketManager class that can keep track of the number of...

    Your assignment is to design a TicketManager class that can keep track of the number of seats available in a theater’s auditorium. The TicketManager class should have a two-Dimensional array, which has 15 rows and 30 columns for all the seats available in the auditorium, also an array of double to keep track of the price of tickets for each row. Each row has a different price. Use the following UML diagram to design the class: -------------------------------------------------------------------- + NUMROWS :...

  • The language is C++ for visual studio express 2013 for windows create a TicketManager class and...

    The language is C++ for visual studio express 2013 for windows create a TicketManager class and a program that uses the class to sell tickets for a performance at a theater. Here are all the specs. This is an intense program, please follow all instructions carefully. -I am only creating the client program that uses the class and all it's functions -The client program is a menu-driven program that provides the user with box office options for a theater and...

  • The Course Project can be started in Week 7 and is due by 11:59 pm CT...

    The Course Project can be started in Week 7 and is due by 11:59 pm CT Saturday of Week 8. It must follow standard code formatting and have a comment block at the top of the code file with a detailed description of what the program does. Functions must have a comment block with a detailed description of what it does. Pseudocode must be provided in the comment block at the top of the file. This program will allow the...

  • Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating...

    Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating pattern: A         1          2          3          4          5          6          7          8          9          ……    100 B         1          2          3          4          5          6          7          8          9          ……    100 AISLE C         1          2          3          4          5          6          7          8          9          ……    100 D         1          2          3          4          5          6          7          8          9          ……    100 Either use 2D STL array (array that contains array) or 4 single dimensional STL arrays of size 100. Write a program to display a menu to the user with the options to reserve a seat of choice, reserve a window seat, reserve an aile seat, reserve a seat (any available), withdraw reservation, update reservation (change seat) and display...

  • For this week's assignment , create and complete a Windows application for the following question. Airline...

    For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and please type 2 for Economy". If the user enters 1, your application should assign a seat in the first class( seats 1-5). If the user...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT