Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lecture 7
- //Author: Roger Nordström s071410
- import java.util.*;
- public class Cinema
- {
- public static void main (String[] args)
- {
- //Variables
- Scanner reader=new Scanner(System.in);
- String[][] seats=new String[5][6];
- int row, seat, input, tickets, count = 0;
- String menu = "Menu: "
- + "\n1: Reserve seats"
- + "\n2: View current seating"
- + "\n0: Quit program";
- //Assigns numbers to the seats.
- for (int i = 0; i<5; i++)
- {
- seats[i][0]=new String("1");
- seats[i][1]=new String("2");
- seats[i][2]=new String("3");
- seats[i][3]=new String("4");
- seats[i][4]=new String("5");
- seats[i][5]=new String("6");
- }
- do
- {
- //Asks the user what she wants to do
- System.out.println("\n"+menu);
- System.out.println("Input (1-2 or 0): ");
- input = Integer.parseInt(reader.next());
- reader.nextLine();
- switch(input)
- {
- case 1:
- //When all the 30 seats are booked, the program informs the user that the
- cinema is full.
- if(count == 30)
- {
- System.out.println("\nThe cinema is fully booked.");
- }
- //If there are seats available
- else
- {
- do
- {
- printArray(seats);
- System.out.print("\nHow many seats would you like to reserve?
- Press 0 to cancel. ");
- tickets = reader.nextInt();
- if(tickets>5)
- {
- System.out.println("The maximum number of seats per
- reservation is 5.");
- }
- if(tickets==0)
- {
- System.out.println("Cancelling the reservation.");
- break;
- }
- if(tickets<0)
- {
- System.out.println("The minimum number of seats per
- reservation is 1.");
- }
- //If there aren't enough seats available for the specific number
- of persons
- if(tickets>(30-count))
- {
- System.out.println("Unfortunately there are only
- "+(30-count)+" seats available.");
- }
- }
- while(tickets>5 || tickets<0 || tickets>(30-count));
- recommendSeats(tickets, seats);
- for(int j=0;j<tickets;j++)
- {
- do
- {
- //Asks the user on what row he would like to book a seat
- System.out.println("\nWhere would person number "+(j+1)+"
- like to sit?");
- do
- {
- System.out.print("Row: ");
- row=reader.nextInt();
- //If the user choses a nonexistent row
- if(row>5 || row<1)
- {
- System.out.println("Please choose a row between 1 and
- 5.");
- }
- }
- while(row>5 || row<1);
- //Asks what seat the user would like.
- do
- {
- System.out.print("Seat: ");
- seat=reader.nextInt();
- //If the user choses a nonexistent seat
- if(seat!=1 && seat!=2 && seat!=3 &&
- seat!=4 && seat!=5 && seat!=6)
- {
- System.out.println("Please choose a seat between 1
- and 6.");
- }
- }
- while(seat!=1 && seat!=2 && seat!=3 && seat!=4 && seat!=5 &&
- seat!=6);
- }
- while(row>5);
- //If the seat is already taken, it informs the user about it
- if(seats[row-1][seat-1].equals("X"))
- {
- System.out.println("\nThat seat is already reserved, please
- select another one.");
- j--;
- }
- //If the seat is free, the program books it and marks it as taken.
- else
- {
- seats[row-1][seat-1] = "X";
- count++;
- }
- }
- }
- break;
- case 2:
- printArray(seats);
- break;
- case 0:
- System.out.println("\nGood bye!");
- break;
- //Informs the user that the input is not valid
- default:
- System.out.println("Invalid input.");
- break;
- }
- }
- //Exits the program
- while(input != 0);
- }
- //This method prints the current seating situation
- public static void printArray(String[][] a)
- {
- //Prints the rows
- System.out.println();
- System.out.println("-SCREEN-");
- for(int i=0;i<5;i++)
- {
- System.out.print(i+1+" ");
- //Prints the seats
- for(int j=0;j<6;j++)
- {
- System.out.print(a[i][j]);
- }
- System.out.print(" ");
- System.out.println();
- }
- }
- //This method recommends the best seats available
- public static void recommendSeats(int tickets, String[][] seats)
- {
- //Variables
- int j;
- //When reserving 1 ticket
- if(tickets == 1)
- {
- //Checks in there are free seats on the 3rd row
- if(!seats[2][0].equals("X") || !seats[2][1].equals("X") ||
- !seats[2][2].equals("X") || !seats[2][3].equals("X") ||
- !seats[2][4].equals("X") || !seats[2][5].equals("X"))
- {
- j=2;
- //Checks what seats are available, starting from the middle
- if(!seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
- }
- else if(!seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
- }
- else if(!seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
- }
- else if(!seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
- }
- else if(!seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
- }
- else if(!seats[j][0].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
- }
- }
- //Checks in there are free seats on the 4th row
- else if(!seats[3][0].equals("X") || !seats[3][1].equals("X") ||
- !seats[3][2].equals("X") || !seats[3][3].equals("X") ||
- !seats[3][4].equals("X") || !seats[3][5].equals("X"))
- {
- j=3;
- if(!seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
- }
- else if(!seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
- }
- else if(!seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
- }
- else if(!seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
- }
- else if(!seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
- }
- else if(!seats[j][0].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
- }
- }
- //Checks in there are free seats on the 2th row, and so on
- else if(!seats[1][0].equals("X") || !seats[1][1].equals("X") ||
- !seats[1][2].equals("X") || !seats[1][3].equals("X") ||
- !seats[1][4].equals("X") || !seats[1][5].equals("X"))
- {
- j=1;
- if(!seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
- }
- else if(!seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
- }
- else if(!seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
- }
- else if(!seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
- }
- else if(!seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
- }
- else if(!seats[j][0].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
- }
- }
- else if(!seats[4][0].equals("X") || !seats[4][1].equals("X") ||
- !seats[4][2].equals("X") || !seats[4][3].equals("X") ||
- !seats[4][4].equals("X") || !seats[4][5].equals("X"))
- {
- j=4;
- if(!seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
- }
- else if(!seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
- }
- else if(!seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
- }
- else if(!seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
- }
- else if(!seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
- }
- else if(!seats[j][0].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
- }
- }
- else if(!seats[0][0].equals("X") || !seats[0][1].equals("X") ||
- !seats[0][2].equals("X") || !seats[0][3].equals("X") ||
- !seats[0][4].equals("X") || !seats[0][5].equals("X"))
- {
- j=0;
- if(!seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 4.");
- }
- else if(!seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 3.");
- }
- else if(!seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 5.");
- }
- else if(!seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 2.");
- }
- else if(!seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 6.");
- }
- else if(!seats[j][0].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seat 1.");
- }
- }
- }
- //When reserving 2 tickets
- if(tickets == 2)
- {
- if(!seats[2][0].equals("X") && !seats[2][1].equals("X") ||
- !seats[2][1].equals("X") && !seats[2][2].equals("X") ||
- !seats[2][2].equals("X") && !seats[2][3].equals("X") ||
- !seats[2][3].equals("X") && !seats[2][4].equals("X") ||
- !seats[2][4].equals("X") && !seats[2][5].equals("X"))
- {
- j=2;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
- 3.");
- }
- else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
- 2.");
- }
- }
- else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") ||
- !seats[3][1].equals("X") && !seats[3][2].equals("X") ||
- !seats[3][2].equals("X") && !seats[3][3].equals("X") ||
- !seats[3][3].equals("X") && !seats[3][4].equals("X") ||
- !seats[3][4].equals("X") && !seats[3][5].equals("X"))
- {
- j=3;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
- 3.");
- }
- else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
- 2.");
- }
- }
- else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") ||
- !seats[1][1].equals("X") && !seats[1][2].equals("X") ||
- !seats[1][2].equals("X") && !seats[1][3].equals("X") ||
- !seats[1][3].equals("X") && !seats[1][4].equals("X") ||
- !seats[1][4].equals("X") && !seats[1][5].equals("X"))
- {
- j=1;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
- 3.");
- }
- else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
- 2.");
- }
- }
- else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") ||
- !seats[4][1].equals("X") && !seats[4][2].equals("X") ||
- !seats[4][2].equals("X") && !seats[4][3].equals("X") ||
- !seats[4][3].equals("X") && !seats[4][4].equals("X") ||
- !seats[4][4].equals("X") && !seats[4][5].equals("X"))
- {
- j=4;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
- 3.");
- }
- else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
- 2.");
- }
- }
- else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") ||
- !seats[0][1].equals("X") && !seats[0][2].equals("X") ||
- !seats[0][2].equals("X") && !seats[0][3].equals("X") ||
- !seats[0][3].equals("X") && !seats[0][4].equals("X") ||
- !seats[0][4].equals("X") && !seats[0][5].equals("X"))
- {
- j=0;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") )
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2 and
- 3.");
- }
- else if(!seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1 and
- 2.");
- }
- }
- //If it is impossible to recommend seats next to each other
- else
- {
- System.out.println("Unfortunately you can't sit next to each other.");
- }
- }
- //When reserving 3 tickets
- if(tickets == 3)
- {
- if(!seats[2][0].equals("X") && !seats[2][1].equals("X") &&
- !seats[2][2].equals("X") ||
- !seats[2][1].equals("X") && !seats[2][2].equals("X") &&
- !seats[2][3].equals("X") ||
- !seats[2][2].equals("X") && !seats[2][3].equals("X") &&
- !seats[2][4].equals("X") ||
- !seats[2][3].equals("X") && !seats[2][4].equals("X") &&
- !seats[2][5].equals("X"))
- {
- j=2;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
- !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
- 3.");
- }
- }
- else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") &&
- !seats[3][2].equals("X") ||
- !seats[3][1].equals("X") && !seats[3][2].equals("X") &&
- !seats[3][3].equals("X") ||
- !seats[3][2].equals("X") && !seats[3][3].equals("X") &&
- !seats[3][4].equals("X") ||
- !seats[3][3].equals("X") && !seats[3][4].equals("X") &&
- !seats[3][5].equals("X"))
- {
- j=3;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
- !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
- 3.");
- }
- }
- else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") &&
- !seats[1][2].equals("X") ||
- !seats[1][1].equals("X") && !seats[1][2].equals("X") &&
- !seats[1][3].equals("X") ||
- !seats[1][2].equals("X") && !seats[1][3].equals("X") &&
- !seats[1][4].equals("X") ||
- !seats[1][3].equals("X") && !seats[1][4].equals("X") &&
- !seats[1][5].equals("X"))
- {
- j=1;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
- !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
- 3.");
- }
- }
- else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") &&
- !seats[4][2].equals("X") ||
- !seats[4][1].equals("X") && !seats[4][2].equals("X") &&
- !seats[4][3].equals("X") ||
- !seats[4][2].equals("X") && !seats[4][3].equals("X") &&
- !seats[4][4].equals("X") ||
- !seats[4][3].equals("X") && !seats[4][4].equals("X") &&
- !seats[4][5].equals("X"))
- {
- j=4;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
- !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
- 3.");
- }
- }
- else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") &&
- !seats[0][2].equals("X") ||
- !seats[0][1].equals("X") && !seats[0][2].equals("X") &&
- !seats[0][3].equals("X") ||
- !seats[0][2].equals("X") && !seats[0][3].equals("X") &&
- !seats[0][4].equals("X") ||
- !seats[0][3].equals("X") && !seats[0][4].equals("X") &&
- !seats[0][5].equals("X"))
- {
- j=0;
- if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4 and
- 5.");
- }
- else if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3 and
- 4.");
- }
- else if(!seats[j][3].equals("X") && !seats[j][4].equals("X") &&
- !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 4, 5 and
- 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2 and
- 3.");
- }
- }
- else
- {
- System.out.println("Unfortunately you can't sit next to each other.");
- }
- }
- //When reserving 4 tickets
- if(tickets == 4)
- {
- if(!seats[2][0].equals("X") && !seats[2][1].equals("X") &&
- !seats[2][2].equals("X") && !seats[2][3].equals("X") ||
- !seats[2][1].equals("X") && !seats[2][2].equals("X") &&
- !seats[2][3].equals("X") && !seats[2][4].equals("X") ||
- !seats[2][2].equals("X") && !seats[2][3].equals("X") &&
- !seats[2][4].equals("X") && !seats[2][5].equals("X"))
- {
- j=2;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
- and 5.");
- }
- else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
- and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
- and 4.");
- }
- }
- else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") &&
- !seats[3][2].equals("X") && !seats[3][3].equals("X") ||
- !seats[3][1].equals("X") && !seats[3][2].equals("X") &&
- !seats[3][3].equals("X") && !seats[3][4].equals("X") ||
- !seats[3][2].equals("X") && !seats[3][3].equals("X") &&
- !seats[3][4].equals("X") && !seats[3][5].equals("X"))
- {
- j=3;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
- and 5.");
- }
- else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
- and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
- and 4.");
- }
- }
- else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") &&
- !seats[1][2].equals("X") && !seats[1][3].equals("X") ||
- !seats[1][1].equals("X") && !seats[1][2].equals("X") &&
- !seats[1][3].equals("X") && !seats[1][4].equals("X") ||
- !seats[1][2].equals("X") && !seats[1][3].equals("X") &&
- !seats[1][4].equals("X") && !seats[1][5].equals("X"))
- {
- j=1;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
- and 5.");
- }
- else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
- and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
- and 4.");
- }
- }
- else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") &&
- !seats[4][2].equals("X") && !seats[4][3].equals("X") ||
- !seats[4][1].equals("X") && !seats[4][2].equals("X") &&
- !seats[4][3].equals("X") && !seats[4][4].equals("X") ||
- !seats[4][2].equals("X") && !seats[4][3].equals("X") &&
- !seats[4][4].equals("X") && !seats[4][5].equals("X"))
- {
- j=4;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
- and 5.");
- }
- else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
- and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
- and 4.");
- }
- }
- else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") &&
- !seats[0][2].equals("X") && !seats[0][3].equals("X") ||
- !seats[0][1].equals("X") && !seats[0][2].equals("X") &&
- !seats[0][3].equals("X") && !seats[0][4].equals("X") ||
- !seats[0][2].equals("X") && !seats[0][3].equals("X") &&
- !seats[0][4].equals("X") && !seats[0][5].equals("X"))
- {
- j=0;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4
- and 5.");
- }
- else if(!seats[j][2].equals("X") && !seats[j][3].equals("X") &&
- !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 3, 4, 5
- and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3
- and 4.");
- }
- }
- else
- {
- System.out.println("Unfortunately you can't sit next to each other.");
- }
- }
- //When reserving 5 tickets
- if(tickets == 5)
- {
- if(!seats[2][0].equals("X") && !seats[2][1].equals("X") &&
- !seats[2][2].equals("X") && !seats[2][3].equals("X") && !seats[2][4].equals("X") ||
- !seats[2][1].equals("X") && !seats[2][2].equals("X") &&
- !seats[2][3].equals("X") && !seats[2][4].equals("X") && !seats[2][5].equals("X"))
- {
- j=2;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
- 5 and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
- 4 and 5.");
- }
- }
- else if(!seats[3][0].equals("X") && !seats[3][1].equals("X") &&
- !seats[3][2].equals("X") && !seats[3][3].equals("X") && !seats[3][4].equals("X") ||
- !seats[3][1].equals("X") && !seats[3][2].equals("X") &&
- !seats[3][3].equals("X") && !seats[3][4].equals("X") && !seats[3][5].equals("X"))
- {
- j=3;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
- 5 and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
- 4 and 5.");
- }
- }
- else if(!seats[1][0].equals("X") && !seats[1][1].equals("X") &&
- !seats[1][2].equals("X") && !seats[1][3].equals("X") && !seats[1][4].equals("X") ||
- !seats[1][1].equals("X") && !seats[1][2].equals("X") &&
- !seats[1][3].equals("X") && !seats[1][4].equals("X") && !seats[1][5].equals("X"))
- {
- j=1;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
- 5 and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
- 4 and 5.");
- }
- }
- else if(!seats[4][0].equals("X") && !seats[4][1].equals("X") &&
- !seats[4][2].equals("X") && !seats[4][3].equals("X") && !seats[4][4].equals("X") ||
- !seats[4][1].equals("X") && !seats[4][2].equals("X") &&
- !seats[4][3].equals("X") && !seats[4][4].equals("X") && !seats[4][5].equals("X"))
- {
- j=4;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
- 5 and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
- 4 and 5.");
- }
- }
- else if(!seats[0][0].equals("X") && !seats[0][1].equals("X") &&
- !seats[0][2].equals("X") && !seats[0][3].equals("X") && !seats[0][4].equals("X") ||
- !seats[0][1].equals("X") && !seats[0][2].equals("X") &&
- !seats[0][3].equals("X") && !seats[0][4].equals("X") && !seats[0][5].equals("X"))
- {
- j=0;
- if(!seats[j][1].equals("X") && !seats[j][2].equals("X") &&
- !seats[j][3].equals("X") && !seats[j][4].equals("X") && !seats[j][5].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 2, 3, 4,
- 5 and 6.");
- }
- else if(!seats[j][0].equals("X") && !seats[j][1].equals("X") &&
- !seats[j][2].equals("X") && !seats[j][3].equals("X") && !seats[j][4].equals("X"))
- {
- System.out.println("Recommended seats: Row "+(j+1)+", seats 1, 2, 3,
- 4 and 5.");
- }
- }
- else
- {
- System.out.println("Unfortunately you can't sit next to each other.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement