Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please see below my code. The program should not crash no matter what is entered. so I'm trying to validate user's input by implementing a

image text in transcribed

Please see below my code. The program should not crash no matter what is entered. so I'm trying to validate user's input by implementing a do while loop but it doesn't seem to be working... I want to do this in the code for seat and price but the program doesn't continue asking the user for input. how can I modify this?

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) { 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;

do {

System.out.print("Please enter the seat by row and column number ( EX: 1 2)--"); while (!scnr.hasNextInt()) { System.err.println("Incorrect value, please insert a valid seat number"); scnr.next(); } r = scnr.nextInt(); c = scnr.nextInt();

//because 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."); } }while(scnr.hasNextInt());

break;

case 'p': case 'P': boolean foundSeat = false;

System.out.print(" please select a price "); int price = scnr.nextInt(); for (int row = 0; row

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; //here 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': System.out.print(" .....available seats..... "); for (int row = 0; row

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_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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago

Question

Which personal relationships influenced you the most?

Answered: 1 week ago