A theater seating chart is implemented as a twodimensional a
Solution
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

