Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 dont 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 TheaterSeatTester class 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 TheaterSeatSeller class 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 the printSeats 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 printSeats method to display the formatted seating chart on request.
  4. Code a getByLoc method. 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 getByPrice method. 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.
  6. Code a getBest method. It has no input parameters and returns a Boolean response indicating success or failure (seat was available or not). Locate the best available seat where best in this case is defined as the highest price seat still availalable closest to the stage. The stage is located in front of the row with the most expensive seats (i.e. the last row in the array). (Note that the best available might not be in the first row even if there are seats available in the first row.) If available, display a message that the seat at that location and that price (name both) will be reserved. Mark the seat sold by changing the price to 0.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Design a job advertisement.

Answered: 1 week ago