Answered step by step
Verified Expert Solution
Question
1 Approved Answer
must be in java: starter code: import java.util.Scanner; public class TheaterSeatSeller { //constants for the size of the theater static final int NUM_ROWS = 9;
must be in java:
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 /ested 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; iP7.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[] [1, you increment pricesAvailable [0]. When you see a value of 20, you increment pricesAvailable [1], and so on up to a value of 50 andpricesAvailable [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 1,357 words s20. 25
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