import java.util.Scanner;
public class Main {
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();
System.out.println();
String[][] arr = createCinema(rows, seats);
while (true) {
System.out.println("1. Show the seats\n" +
"2. Buy a ticket\n" +
"3. Statistics\n" +
"0. Exit");
int choice = scanner.nextInt();
if (choice == 1) {
printCinema(arr);
} else if (choice == 2) {
System.out.println("Enter a row number: ");
int checkRow = scanner.nextInt();
System.out.println("Enter a seat number in that row: ");
int checkSeat = scanner.nextInt();
ticketPrice(rows, seats, checkRow);
arr[checkRow][checkSeat] = "B";
} else if (choice == 3) {
int countOfTickets = 0;
int count = 0;
double percentage;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (arr[i][j].equals("B")) {
countOfTickets++;
count += currentIncome(rows, seats, i);
}
}
}
percentage = (double) Math.round(count * 100) / totalIncome(rows, seats);
System.out.println("Number of purchased tickets: " + countOfTickets);
System.out.print("Percentage: ");
System.out.format("%.2f", percentage);
System.out.println("%");
System.out.println("Current income: $" + count);
System.out.println("Total income: $" + totalIncome(rows, seats));
} else if (choice == 0) {
break;
}
}
}
public static String[][] createCinema(int rows, int seats) {
String[][] arr = new String[rows + 1][seats + 1];
int count = 1;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (i == 0 && j == 0) {
arr[i][j] = " ";
} else {
arr[i][j] = String.valueOf(count);
count++;
}
if (i > 0 && j == 0) {
arr[i][j] = String.valueOf(i);
} else if (i > 0 && j > 0) {
arr[i][j] = "S";
}
}
}
return arr;
}
public static void printCinema(String[][] cinema) {
System.out.println();
System.out.println("Cinema: ");
for (int i = 0; i < cinema.length; i++) {
for (int j = 0; j < cinema[i].length; j++) {
System.out.print(cinema[i][j]);
System.out.print(" ");
}
System.out.println();
}
System.out.println();
}
public static void ticketPrice(int rows, int seats, int checkRow) {
System.out.println();
if (rows * seats <= 60) {
System.out.println("Ticket price: $10");
} else {
if (rows % 2 == 0) {
if (checkRow <= rows / 2) {
System.out.println("Ticket price: $10");
} else {
System.out.println("Ticket price: $8");
}
} else {
if (checkRow <= rows / 2) {
System.out.println("Ticket price: $10");
} else {
System.out.println("Ticket price: $8");
}
}
}
}
public static int currentIncome(int rows, int seats, int checkRow) {
if (rows * seats <= 60) {
return 10;
} else {
if (rows % 2 == 0) {
if (checkRow <= rows / 2) {
return 10;
} else {
return 8;
}
} else {
if (checkRow <= rows / 2) {
return 10;
} else {
return 8;
}
}
}
}
public static int totalIncome(int rows, int seats) {
return rows * seats * 10;
}
}
public static void ticketPrice(int rows, int seats, int checkRow) {
System.out.println();
if (rows * seats <= 60) {
System.out.println("Ticket price: $10");
} else {
if (rows % 2 == 0) {
if (checkRow <= rows / 2) {
System.out.println("Ticket price: $10");
} else {
System.out.println("Ticket price: $8");
}
} else {
if (checkRow <= rows / 2) {
System.out.println("Ticket price: $10");
} else {
System.out.println("Ticket price: $8");
}
}
}
}