Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having some trouble getting my code to compile. Does anyone have any advice on how I can fix it? (See Attached Photo's for problem

I'm having some trouble getting my code to compile. Does anyone have any advice on how I can fix it? (See Attached Photo's for problem question). image text in transcribedimage text in transcribedimage text in transcribed

import java.util.Scanner;

public class TheaterSeatSeller { //public static void main(String[] args) { //constants for the size of the theater static final int NUM_ROWS = 9; static final int NUM_COLS = 10; int[] pricesAvailable = {0,0,0,0,0}; //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[][] 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]; ... for (int i = 0; i

while (running) {// main execution loop userInput = myScanner.next(); // get input & set menu options here if (userInput.charAt(0) == 'Q' || userInput.charAt(0) == 'q') { // 1) quit System.out.println("Thank you for your purchase!"); break; } else if (userInput.charAt(0) == 'P' || userInput.charAt(0) == 'p') { System.out.println("You chose: Price"); System.out.print("Enter Price (10,20,30,40,50):"); int price = 0; userInput = myScanner.next(); System.out.println(); if (userInput.equals("10") || userInput.equals("20") || userInput.equals("30") || userInput.equals("40") || userInput.equals("50")) {

price = Integer.parseInt(userInput); if (getByPrice(price)) { System.out.println("Congratulations, you purchased a ticket for $" + price); } else { System.out.println("Sorry, no more tickets available for this price"); } } else { System.out.println("Invalid Entry."); //bad input } } else if(userInput.charAt(0)=='L' || userInput.charAt(0) == 'l') { System.out.println("You chose option: Location"); System.out.println("Enter Row and Column separated by a space:"); int row = -1; int col = -1; //holds location if(myScanner.hasNextInt()) { row = myScanner.nextInt(); if(myScanner.hasNextInt()) { col = myScanner.nextInt(); if (getByLoc(row, col)) { System.out.println("Congratulations, you purchased a ticket for at: " +row+", " + col); } else { System.out.println("Sorry, no ticket available at this location."); } } else { //invalid, not an int System.out.println("Invalid Entry, use Integer"); //flush input userInput = myScanner.next(); } } else { System.out.println("Invalid Entry, use Integer"); //flush input userInput = myScanner.next(); } } else if(userInput.charAt(0)=='R' || userInput.charAt(0) == 'r') { printSeats(); } else {//error System.out.println("Error, please choose P, L or Q"); } //blank line before next prompt System.out.println(); //prompt for next input System.out.println("Purchase by (P)rice or (L)ocation, P(R)INT, (Q)uit"); } myScanner.close(); //close resource when done. } }

P7.5 - A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: (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 in LabslLab2 folder 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 seatss [ ] [ ] 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

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

Step: 3

blur-text-image

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

Students also viewed these Databases questions

Question

The weak link in the behaviour modelling method is always

Answered: 1 week ago