Untitled
unknown
plain_text
3 years ago
2.7 kB
4
Indexable
import java.util.Scanner;
public class Main {
public static void showMenu() {
System.out.println("1. Show the seats");
System.out.println("2. Buy a ticket");
System.out.println("0. Exit");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of rows:");
int rows = scanner.nextInt();
System.out.println("Enter the number of seats in each row:");
int seats = scanner.nextInt();
int allSeats = rows * seats;
int ticketsUpper = 10;
int ticketsLower = 8;
System.out.println("Cinema:");
for (int i = 0; i < (rows + 1); i++) {
for (int j = 0; j < (seats + 1); j++) {
if (i == 0 && j == 0) {
System.out.print(" ");
} else if (i == 0 && j > 0) {
System.out.print(j + " ");
} else if (i > 0) {
if (j == 0) {
System.out.print(i + " ");
} else {
System.out.print("S ");
}
}
}
System.out.println();
}
while (true) {
showMenu();
}
System.out.println("Enter a row number:");
int rowNumber = scanner.nextInt();
System.out.println("Enter a seat number in that row:");
int seatNumber = scanner.nextInt();
if (allSeats >= 60) {
if (rowNumber <= (rows / 2)) {
System.out.printf("Ticket price: $%d\n", ticketsUpper);
} else {
System.out.printf("Ticket price: $%d\n", ticketsLower);
}
} else {
System.out.printf("Ticket price: $%d\n", ticketsUpper);
}
System.out.println("Cinema:");
for (int i = 0; i < (rows + 1); i++) {
for (int j = 0; j < (seats + 1); j++) {
if (i == 0 && j == 0) {
System.out.print(" ");
} else if (i == 0 && j > 0) {
System.out.print(j + " ");
} else if (i > 0) {
if (j == 0) {
System.out.print(i + " ");
} else if ((i == rowNumber) && (j == seatNumber)) {
System.out.print("B ");
} else {
System.out.print("S ");
}
}
}
System.out.println();
}
}
}
Editor is loading...