A theater seating chart is implemented as a two-dimensional array of ticket pric
ID: 3933760 • Letter: A
Question
A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: Write a program that prompts users to pick a price. Mark sold seats by changing the price to 0. When a user specifies a price, make sure it is available. You will write atleast 3 methods. One method that reads, validates and returns the price. The other that checks whether a seat at that price is available? The third method prints a confirmation if the seat is available or prints a message saying "A seat at this price is not available. Good Bye. Please pick a price: 10 Checking for the availability.. You seat is confirmed! Enjoy your movie Please pick a price: 200 Checking for the availability... A seat at this price is not available Good ByeExplanation / Answer
import java.util.Scanner;
public class TheaterSeatingChart {
static int[][] priceSeatingChart = {
{ 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, 20, 30, 40, 50, 50, 40, 30, 20, 20 },
{ 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 } };
/**
* @param args
*/
public static void main(String[] args) {
int selectPrice = getPrice();
printConfirmation(checkAvailability(selectPrice));
}
/**
* @param flag
*/
public static void printConfirmation(boolean flag) {
if (flag) {
System.out.println("Your Seat is confirmed! Enjoy your movie");
} else {
System.out
.println("A Seat at this price is not available. Good Bye");
}
}
/**
* @return
*/
public static int getPrice() {
Scanner scanner = new Scanner(System.in);
System.out.print("Please pick a price: ");
int selectPrice = scanner.nextInt();
return selectPrice;
}
/**
* @param selectPrice
* @return
*/
public static boolean checkAvailability(int selectPrice) {
System.out.println("Checking for the Availability... ...");
for (int i = 0; i < priceSeatingChart.length; i++) {
for (int j = 0; j < priceSeatingChart[i].length; j++) {
if (priceSeatingChart[i][j] == selectPrice) {
priceSeatingChart[i][j] = 0;
return true;
}
}
}
return false;
}
}
OUTPUT:
Please pick a price: 20
Checking for the Availability... ...
Your Seat is confirmed! Enjoy your movie
Please pick a price: 200
Checking for the Availability... ...
A Seat at this price is not available. Good Bye
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.