Java/JetBrain Project

JetBrain [Easy] Cinema Room Manager - Stage 3

aliceintr 2020. 12. 5. 14:51
반응형

stage 3 문제 시작 !

필요로 하는 자바 컨셉들

 

드디어 좌석을 보여줘서 해당 좌석가격을 보여주는 프로그램 단계이다.

해당강의에서는 Array 를 사용해서 문제를 푸는것 같은데 Array 를 안쓰고 문제를 풀었다.

import java.util.Scanner;

public class Cinema_UserInput {
    public static void main(String[] args) {


        final int PRICE_CHEAP = 8;
        final int PRICE_NORMAL = 10;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number of rows:");
        int rows = sc.nextInt();
        System.out.println("Enter the number of seats in each row:");
        int seats = sc.nextInt();
        System.out.println();
        System.out.println("Cinema:");
        System.out.print("  ");
        for (int i = 1; i<=seats;i++){
            System.out.print(i+" ");
        }
        System.out.println();
        for (int i = 1; i<=rows;i++){
            System.out.print(i);
            System.out.print(" ");
            for (int j = 0; j<seats;j++){
                System.out.print("S");
                System.out.print(" ");
            }
            System.out.println();
        }

        System.out.println();
        System.out.println("Enter a row number:");
        int selectedrow =0;
        //condition 1 : rows lower than 9
        do {
            selectedrow = sc.nextInt();
        }while((selectedrow <= 0) || (selectedrow > rows));

        System.out.println("Enter a seat number in that row:");
        int seat = 0;
        do {
            seat = sc.nextInt();
        }while((seat <= 0) || (seat > seats));


        int totalSeats = rows*seats;
        long ticketPrice = 0;
        int half = 0;
        if(totalSeats > 60){
            if(rows%2 ==0){
                half = rows/2;
                if (selectedrow > half){
                    ticketPrice = PRICE_CHEAP;
                }else {
                    ticketPrice = PRICE_NORMAL;
                }

            }else{
                half = rows/2;
                if (selectedrow > half){
                    ticketPrice = PRICE_CHEAP;
                }else {
                    ticketPrice = PRICE_NORMAL;
                }
            }

        }else{
            ticketPrice = PRICE_NORMAL;
        }

        System.out.println("Ticket price: $"+ticketPrice);

        System.out.println();
        System.out.println("Cinema:");
        System.out.print("  ");
        for (int i = 1; i<=seats;i++){
            System.out.print(i+" ");
        }
        System.out.println();
        for (int i = 1; i<=rows;i++){
            System.out.print(i);
            System.out.print(" ");
            for (int j = 0; j<seats;j++){
                if((i == selectedrow) && (j == seat-1)) {
                    System.out.print("B");
                    System.out.print(" ");
                }else{
                    System.out.print("S");
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}

 

반응형