Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please see below my code. The part that needs to be corrected is bold. When the user enters 0 0 or 0 13 etc... the

image text in transcribed

Please see below my code. The part that needs to be corrected is bold. When the user enters 0 0 or 0 13 etc... the program cannot crash instead we need to make the user enter a correct value.

package seatingchart;

import java.util.Scanner;

/**

*

* @author

*/

public class SeatingChart {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int[][] seatsArr = {

{30, 40, 50, 50, 50, 50, 50, 50, 50, 50, 40, 30},

{30, 30, 40, 40, 50, 50, 50, 50, 40, 40, 30, 30},

{20, 30, 30, 40, 40, 40, 40, 40, 40, 30, 30, 20},

{20, 30, 30, 40, 40, 40, 40, 40, 40, 30, 30, 20},

{20, 20, 30, 30, 40, 40, 40, 40, 30, 30, 20, 20},

{20, 20, 30, 30, 40, 40, 40, 40, 30, 30, 20, 20},

{10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 10, 10},

{10, 10, 20, 20, 20, 20, 20, 20, 20, 20, 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}};

while (true) { //This loop will allow the user to keep entering slections until he or she wants to quit

System.out.println("MENU "

+ " Press s - If you would like to pick a seat" + " "

+ " Press p - if you would like to pick seat by price" + " "

+ " Press d - If you would like a display of available seats" + " " + " q-Quit" + " " + "Choose an option");

char option = scnr.next().charAt(0);

switch (option) {

case 's':

case 'S':

int r = 0;

int c = 0;

System.out.print("Please enter the seat by row and column number ( Ex: 1 2)--");

while (!scnr.hasNextInt()) {

System.out.println("Incorrect!, please insert a valid seat number");

scnr.next();

}

r = scnr.nextInt();

// validate user input

while (!scnr.hasNextInt()) {

System.out.println("Incorrect!, please insert a valid seat number");

scnr.next();

}

c = scnr.nextInt();

if ((r 10) && (c 12)) {

System.out.println("Incorrect value, please insert a valid seat number");

}

//array will start from (0,0) so 1,1 will be at 0,0

if (seatsArr[r - 1][c - 1] != 0) {

System.out.printf("Seat [%d %d] is available ! ", r, c);

// The Seat is found , so we will made the value of seatsArr[row][col]=0 , so

// that it can show status sold

seatsArr[r - 1][c - 1] = 0;

} else {

System.out.println("The seat is not available, please choose another seat.");

}

break;

case 'p':

case 'P':

boolean foundSeat = false;

System.out.print(" please select a price ");

// validate user input

while (!scnr.hasNextInt()) {

System.err.println("Incorrect!, please insert a valid price ");

scnr.next();

}

int price = scnr.nextInt();

for (int row = 0; row

for (int col = 0; col

if (seatsArr[row][col] == price) {

foundSeat = true;

System.out.printf("Seat [%d %d] is available for that price! ", row + 1, col + 1);

//The Seat is found , so we will made the value of seatsArr[row][col]=0 , so that it can show status sold

seatsArr[row][col] = 0;

//allocate first available seat at this price

break;

}

}

if (foundSeat) {

break;

}

}

if (!foundSeat) {

System.out.println("We do not have any seat available at that price");

}

break;

case 'd':

case 'D': //display the array

System.out.print(" .....available seats..... ");

for (int row = 0; row

for (int col = 0; col

System.out.print(seatsArr[row][col] + " ");

}

System.out.println();

}

break;

case 'q':

case 'Q':

System.exit(0);

break;

}

}

}

}

Write a program to implement a theater seating chart. The seating chart should be implemented as a two-dimensional array of ticket prices. Start with the array as follows with these prices in dollars. The array should be initialized in the code without any outside files. 30 40 50 50 50 50 50 50 50 50 40 30 30 30 40 40 50 50 50 50 40 40 30 30 20 30 30 40 40 40 40 40 40 30 30 20 20 30 30 40 40 40 40 40 40 30 30 20 20 20 30 30 40 40 40 40 30 30 20 20 20 20 30 30 40 40 40 40 30 30 20 20 10 10 20 20 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 20 20 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 Allow the user to pick either a seat or a price or a display. Allow the user to enter s for seat, p for price, d for display, or q to quit. Mark sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price. If the user asks for a display of the available seats, show something like what is shown above so they can see what seat they want to choose. The seat in the bottom left corner could be chosen by entering 1 1 at the command line Provide a main method that shows the implementation of your theater seating program. You should allow the user to keep entering selections until he or she wants to quit. Make sure all instructions are clear so the user knows what to do next. The class name should be SeatingChart.java. The program should not crash no matter what is entered

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Question Can a self-employed person adopt a money purchase plan?

Answered: 1 week ago