Results 1 to 3 of 3
- 12-16-2012, 08:35 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
A reservation system for a movie theater, help needed
Hi guys,
I have a home assignment where I should write a reservation system for a movie theater. I have come quite far, but I'm having problems with the following part of the assignment:
I would appreciate it very much if you could give me some pointers. Here's my current code:When user has inputted the number of desired seats, the application should be able to recommend seats for the user following some logic. Normally, if a user wants to reserve more than one ticket, the application should recommend seats that are a) primarily next to each other, and b) secondarily in the middle (rows) of the theater.
andJava Code:import java.util.*; public class Cinema { public static void main (String[] args) { //Variables Scanner reader=new Scanner(System.in); Seat[][] seats=new Seat[5][6]; int row, input, howmany, count = 0; String name; String menu = "Menu: " + "\n1: Book seats" + "\n2: View current seating" + "\n0: Quit program"; //Assigns numbers to the seats. for (int i = 0; i<5; i++) { seats[i][0]=new Seat("1"); seats[i][1]=new Seat("2"); seats[i][2]=new Seat("3"); seats[i][3]=new Seat("4"); seats[i][4]=new Seat("5"); seats[i][5]=new Seat("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."); } else { do { System.out.print("How many seats would you like to book? "); howmany = reader.nextInt(); if(howmany>5) { System.out.println("The maximum number of seats per booking is 5."); } if(howmany<1) { System.out.println("The minimum number of seats per booking is 1."); } } while(howmany>5 || howmany<1); for(int j=0;j<howmany;j++) { printArray(seats); do { //Asks the user on what row he would like to book a seat System.out.println("Where 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) { System.out.println("There are only 5 rows, please choose a new row."); } } while(row>5); //Asks what seat the user would like. do { System.out.print("Seat: "); name=reader.next(); //If the user choses a nonexistent seat if(!name.equals("1") && !name.equals("2") && !name.equals("3") && !name.equals("4") && !name.equals("5") && !name.equals("6")) { System.out.println("There are only 6 seats per row, please choose a new seat."); } } while(!name.equals("1") && !name.equals("2") && !name.equals("3") && !name.equals("4") && !name.equals("5") && !name.equals("6")); } while(row>5); for(int i=0;i<6;i++) { if(seats[row-1][i].getName().equalsIgnoreCase(name)) { //If the seat is already taken, it informs the user about it if(seats[row-1][i].getVisible()==false) { System.out.println("\nThat seat is already taken, please select another one.\n"); j--; } //If the seat is free, the program books it and marks it as taken. else { seats[row-1][i].setVisible(false); count++; } } } } } break; case 2: printArray(seats); break; case 0: System.out.println("Good bye!"); break; default: //Informs the user that the input is not valid System.out.println("Invalid input."); break; } } while(input != 0); } //This method prints the current seating situation public static void printArray(Seat[][] a) { //Prints the rows 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(); } } }
Java Code:public class Seat { //Variables. private boolean visible; private String name; public Seat(String name) { visible=true; this.name=name; } public void setVisible(boolean b) { visible=b; } public String getName() { return name; } public boolean getVisible() { return visible; } public String toString() { if(visible) return name; else return "X"; } }
- 12-16-2012, 09:53 PM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: A reservation system for a movie theater, help needed
Well I will not do the homework for you... how about just:
if a user wants to reserve more than one ticket, look for
a) primarily next to each other
b) secondarily in the middle (rows) of the theater.
That needs you to define what the middle rows are and implement a method that checks if near the requested seat are 'n' other ones where n is the number of requested seats?I like likes!.gif)
- 12-17-2012, 12:27 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Pizza ordering system - university project urgent help needed!
By JavaCake in forum New To JavaReplies: 10Last Post: 12-12-2012, 12:04 PM -
Airplane Reservation
By RiterHeng in forum New To JavaReplies: 5Last Post: 04-20-2012, 12:21 PM -
flight reservation system...need help with the booking section. thanks
By codename47 in forum New To JavaReplies: 3Last Post: 12-18-2011, 12:11 PM -
Hotel Reservation in JAVA (help)
By BattalGazi in forum New To JavaReplies: 4Last Post: 07-31-2011, 08:32 PM -
java reservation class plane seat and reservation classes
By cool_guy364 in forum Advanced JavaReplies: 2Last Post: 10-15-2009, 09:56 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks