Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. //Lecture 7 //Author: Roger Nordström s071410
  2.  
  3. 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."); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement