Question
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
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 - these values will be stored as constants in our class).
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 price, find any seat with that price (iterate over the array one element at a time). Alternately, users can select a seat by specifying a row and a column.
I have again given you a starter shell code for this lab assignment. It is posted on Google Drive as TheaterSeatSeller.java. There are FOUR (4) methods that you must complete, as detailed below.
First you must complete the constructor public TheaterSeatSeller(){...}. In this method, you need to fill in the pricesAvailable[] array (instance variable of our class). You will do this by iterating over the seats[][] array. When you encounter a value of 10 in seats[][], you increment pricesAvailable[0]. When you see a value of 20, you increment pricesAvailable[1], and so on up to a value of 50 and pricesAvailable[4]. At the end of this method, pricesAvailable[] should contain an entry for the number of tickets available at each prices ([0] # of $10 tickets, [1] 20, [2] 30, [3] 40, [4] 50).
Second you must add to the printSeats(){...} method. This method already prints out the entire theater showing ticket prices, and available seats. (Available seats show the price, unavailable seats show a 0). Your task for this method, is to add some information to the printout. After the seating chart has been printed, you must add a line (or lines) that display the number of each priced seat available. (recall, we are storing this information in the pricesAvailable[] array). For example, you might print out the following after the seats have been printed:
Tickets available by price:
$10: 25
$20: 6
$30: 3
$40: 4
$50: 5
Third you must complete the public boolean getByPrice(int price){...} method. If there is an available ticket with the given price, then you will mark that location in the seats[][] array with a 0, and return true. If there is no ticket left with the given price, do not change the seats[][] array, and return false.
Fourth you must complete the public boolean getByLoc(int row, int col){...} method. If there is a seat available indicated by parameters row and col, then you will mark that location in the seats[][] array with a 0, and return true. Otherwise, make no changes to the seats[][] array and return false.
You should test all aspects of your program to ensure that it works correctly. I will also provide a file called tests.txt which will run through multiple tests in a single batch operation (Instructions on how to use this file for input are given below in the next paragraph). The provided file buys all $50 tickets, and then attempts to keep buying. (Program should not crash, but indicate no more tickets are available at this price). Then the tests.txt file tries to buy 0,0; 0,1; 0, 2; and 0, 4. Finally, the tests.txt file uses a Q to quit the program. The text that you enter into the tests.txt file is simply the menu commands and inputs that you would give to the program if you were interacting with it in real time. Look at the tests.txt file so that you can add your own tests. (for example, you should try to buy 0,0; then try to buy it again, and make sure your program sells the ticket on the first try, and reports that the ticket is not available on the second try).
To use the file tests.txt you must have your TheaterSeatSeller.class file and tests.txt file in the same directory/folder. (note this is the .class file, NOT the .java file - usually contained in a "bin" directory in eclipse, and it is in your main project directory in BlueJ). Next, you need to navigate through the command line to the folder where both of these files are located. (There is a shortcut in windows, right click the folder where you want to open a command line, and you get an option to "Open command window here." You can then type:
java TheaterSeatSeller < tests.txt
This will run your program, and enter all the text from your tests.txt file into the program as if you had entered it in manually. You must test many aspects of your program, so this will allow you to create a "batch test" where you can run a test with a single command, fix bugs, and then run the test again. I will be creating an ultimate batch test that will test all aspects of your methods to help me to determine your final score.
Starter Code
import java.util.Scanner; public class TheaterSeatSeller { //constants for the size of the theater static final int NUM_ROWS = 9; static final int NUM_COLS = 10; //array that tracks how many tickets of each price that are still //available. loc[0] is $10, loc[1] is $20, ..., loc[4] is $50 //this variable must be initialized inside of the constructor int[] pricesAvailable = {0,0,0,0,0}; //5 ticket prices, 10,20,30,40,50 //ticket prices, a value of 0 will represent a seat that //has been sold 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} }; //************************constructor You must fill this in! public TheaterSeatSeller() { //****************HERE You must set the pricesAvailable[] array. //hint: Iterate over the seats[][] array //if the value in the seats array is 10, increment pricesAvailable[0]; //if the value in seats[][] is 20, increment pricesAvailable[1]; ... etc //I do NOT want you to simply count by hand the number of each ticket //in the seats array. You need to loop through the seats array with //nested for loops, and update the pricesAvailable array } //a method to print the current seats array //a 0 represents an empty seat //******************You must insert code into this method in order to //***********Also print the number of available tickets at each price public void printSeats() { //blank line System.out.println(); //print spacer System.out.print(" "); //print column headings for(int i = 0; i text.txt
P 50 P 50 P 50 P 50 P 50 P 50 P 50 P 50 P 50 P 50 L 0 0 L 0 1 L 0 2 L 0 3 L 0 4 Q
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started