Untitled

 avatar
unknown
plain_text
2 years ago
3.0 kB
3
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 showRoom(int rows, int seats) {
        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();
        }
    }
    

    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;
        int rowNumber = -1;
        int seatNumber = -1
        
        
        while (true) {
            showMenu();
            int answer = scanner.nextInt();
            if (answer == 0) {
                break;
            } else if (answer == 1){
                showRoom();
            }
        }
        
        
        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...