Results 1 to 6 of 6
  1. #1
    Jubic is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Question Difficulty in booking movie tickets

    Once again, hey to all JF Members :D
    Right now, I'm doing an assignment on Movie Booking. And I'm having problems booking movie tickets, then update the member's purchased ticket count; and marking an X on the seat to specify that it's booked. FYI, I'm using 2D Array for the seats.

    Java Code:
    else if (menuChoice == 4) {
    				// Login > Choose Hall > Movie > If tickets bought = > 4, System.out.println("cannot book more than 4 tic);
    				//Book ticket
    				System.out.println("Entering Booking System. ");
    				System.out.println("Please enter member name: ");
    				String name = userInputS.nextLine();
    				System.out.println("Please enter member password: ");
    				String password = userInputS.nextLine();
    				
    				for (Member member : memberList) { 
    					
    					/*if(member.name !=name && member.password != password) {
    						System.out.println("Either one or both of your entered credentials is incorrect, please try again.");
    						break;
    					}*/ // can't seem to work :l
    					
    					if (member.name.equalsIgnoreCase(name) && member.password.equalsIgnoreCase(password)) {
    						
    						System.out.println("Please choose the hall you wish to watch in: ");
    						System.out.println("1. Hall 1");
    						System.out.println("2. Hall 2");
    						System.out.println("3. Hall 3");
    						System.out.print("Enter your choice :  ");
    						int hallChoice = userInputI.nextInt();
    							
    						while (hallChoice != 1 && hallChoice !=2 && hallChoice != 3){
    
    							System.out.println("Please enter again! Invalid option!");
    							System.out.println("\t1. Hall 1");
    							System.out.println("\t2. Hall 2");
    							System.out.println("\t3. Hall 3");
    							System.out.print("\nEnter your choice :  ");
    							hallChoice = userInputI.nextInt();
    								
    						}
    							
    							String Letters[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    							if (hallChoice == 1) {
    
    								System.out.println("Please choose your preferred movie: ");
    							    userInputS.nextLine();
    							    
    							    System.out.println("Please enter the number of tickets you wish to buy");
    							    @SuppressWarnings("unused")
    								int noOfTickets = userInputI.nextInt();
    							    
    								String[][]Hall1 = new String[5][6];
    								System.out.println("X = Seat taken");
    
    							    System.out.println("\n\t<<------------ SCREEN ------------ >>");
    
    							    for(int i = 0; i<5; i++){
    							    	
    							    	System.out.println();
    							    	for(int j = 0; j<6; j++){
    							    		
    							    		System.out.print(Hall1[i][j] = Letters[i] + (j+1+"[ ]") + " ");
    							    		
    							    	}
    							    	
    							    }
    
    							    System.out.println("");
    							    System.out.println("");
    							    System.out.println("Please choose your preferred seat(s): ");
    							    userInputS.nextLine();
    								
    							} else if (hallChoice == 2) {
    
    								System.out.println("Please choose your preferred movie: ");
    							    userInputS.nextLine();
    							    
    							    System.out.println("Please enter the number of tickets you wish to buy");
    							    @SuppressWarnings("unused")
    								int noOfTickets = userInputI.nextInt();
    							    String[][]Hall2 = new String[10][10];
    							    
    							    System.out.println("X = Seat taken");
    
    							    System.out.println("\n\t<<------------ SCREEN ------------ >>");
    
    							    for(int i = 0; i<10; i++){
    							    	
    							    	System.out.println();
    							    	for(int j = 0; j<10; j++){
    							    		
    							    		System.out.print(Hall2[i][j] = Letters[i] + (j+1+"[ ]") + " ");
    							    		
    							    	}
    							    	
    							    }
    
    							    System.out.println("");
    							    System.out.println("");
    							    System.out.println("Please choose your preferred seat(s): ");
    							    userInputS.nextLine();
    								
    							} else if (hallChoice == 3) {
    
    
    								System.out.println("Please choose your preferred movie: ");
    							    userInputS.nextLine();
    							    
    							    System.out.println("Please enter the number of tickets you wish to buy");
    							    @SuppressWarnings("unused")
    								int noOfTickets = userInputI.nextInt();
    
    								String[][]Hall3 = new String[12][10];
    								 
    							    System.out.println("X = Seat taken");
    
    							    System.out.println("\n\t<<------------ SCREEN ------------ >>");
    
    							    for(int i = 0; i<12; i++){
    							    	
    							    	System.out.println();
    							        for(int j = 0; j<10; j++){
    							        	
    							        	System.out.print(Hall3[i][j] = Letters[i] + (j+1+"[ ]") + "\t");
    							        	
    							        }
    							        
    							    }
    
    							    System.out.println("");
    							    System.out.println("");
    							    System.out.println("Please choose your preferred seat(s): ");
    							    userInputS.nextLine();
    								
    							}
    						
    						}
    						
    					}
    					
    			}
    +rep if you helped, even if it doesn't make sense :p
    Last edited by Jubic; 07-24-2010 at 06:30 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Do you have any design/logic for what the code you're having problems with is supposed to do and how the code is going to do it?

    I don't see very many comments in your code describing its logic.

    For example what does this mean: (menuChoice == 4) or this (hallChoice == 3)
    You code creates several 2 dimensional String arrays as local variables. What are they for?
    Local variables disappear when they go out of scope.


    Can you show what you code currently does and what's wrong with it and how you want to change it?

  3. #3
    Jubic is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    You mean the output?

    ------------ CHOOSE YOUR OPTION ------------
    1. Display Members By Roles
    2. Register As A New Club Member (Normal/Silver/Gold)
    3. Display Movie Titles by Halls
    4. Book A Movie Ticket (Incomplete)
    9. Logout

    Enter your choice: 3
    Please enter the hall to show what movies are available: Hall 2
    Title Time Tickets Sold Premier
    ================================================== ================================================== ===================
    Toy Story 3 3pm 80 false
    Toy Story 3 5pm 95 false
    Inception 7pm 97 false
    Inception 9pm 88 false
    ================================================== ================================================== ===================
    ------------ CHOOSE YOUR OPTION ------------
    1. Display Members By Roles
    2. Register As A New Club Member (Normal/Silver/Gold)
    3. Display Movie Titles by Halls
    4. Book A Movie Ticket (Incomplete)
    9. Logout

    Enter your choice: 4
    Entering Booking System.
    Please enter member name:
    Gordan Tan
    Please enter member password:
    C789
    Please choose the hall you wish to watch in:
    1. Hall 1
    2. Hall 2
    3. Hall 3
    Enter your choice : 2
    Please choose your preferred movie:
    Inception
    Please enter the number of tickets you wish to buy
    1
    X = Seat taken

    <<------------ SCREEN ------------ >>

    A1[ ] A2[ ] A3[ ] A4[ ] A5[ ] A6[ ] A7[ ] A8[ ] A9[ ] A10[ ]
    B1[ ] B2[ ] B3[ ] B4[ ] B5[ ] B6[ ] B7[ ] B8[ ] B9[ ] B10[ ]
    C1[ ] C2[ ] C3[ ] C4[ ] C5[ ] C6[ ] C7[ ] C8[ ] C9[ ] C10[ ]
    D1[ ] D2[ ] D3[ ] D4[ ] D5[ ] D6[ ] D7[ ] D8[ ] D9[ ] D10[ ]
    E1[ ] E2[ ] E3[ ] E4[ ] E5[ ] E6[ ] E7[ ] E8[ ] E9[ ] E10[ ]
    F1[ ] F2[ ] F3[ ] F4[ ] F5[ ] F6[ ] F7[ ] F8[ ] F9[ ] F10[ ]
    G1[ ] G2[ ] G3[ ] G4[ ] G5[ ] G6[ ] G7[ ] G8[ ] G9[ ] G10[ ]
    H1[ ] H2[ ] H3[ ] H4[ ] H5[ ] H6[ ] H7[ ] H8[ ] H9[ ] H10[ ]
    I1[ ] I2[ ] I3[ ] I4[ ] I5[ ] I6[ ] I7[ ] I8[ ] I9[ ] I10[ ]
    J1[ ] J2[ ] J3[ ] J4[ ] J5[ ] J6[ ] J7[ ] J8[ ] J9[ ] J10[ ]

    Please choose your preferred seat(s):
    E6
    Please confirm your choice:
    Yes
    After choosing the seats, it should mark an X between the [ ] and asks the member to confirm.

    Java Code:
    String Letters[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    The above code is used for printing the seats, along with the below code:

    Java Code:
    String[][]Hall1 = new String[5][6];
    								System.out.println("X = Seat taken");
    
    							    System.out.println("\n\t<<------------ SCREEN ------------ >>");
    
    							    for(int i = 0; i<5; i++){
    							    	
    							    	System.out.println();
    							    	for(int j = 0; j<6; j++){
    							    		
    							    		System.out.print(Hall1[i][j] = Letters[i] + (j+1+"[ ]") + " ");
    							    		
    							    	}
    							    	
    							    }
    About the (menuChoice) & (hallChoice), it's because I'm supposed to employ a menu-driven application. (menuChoice) is the main menu:

    ------------ CHOOSE YOUR OPTION ------------
    1. Display Members By Roles
    2. Register As A New Club Member (Normal/Silver/Gold)
    3. Display Movie Titles by Halls
    4. Book A Movie Ticket (Incomplete)
    9. Logout
    While (hallChoice) is the menu for the user to choose a movie hall to watch his movie in:

    Please choose the hall you wish to watch in:
    1. Hall 1
    2. Hall 2
    3. Hall 3
    Lastly, I don't quite get what you meant by

    Local variables disappear when they go out of scope.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Local variables disappear when they go out of scope.
    Scope is an important concept. You need to read up on it.

    An example from your code:
    String[][]Hall2 = new String[10][10];
    You define the Hall2 variable within the {} for a if() statement.
    When the code execution crosses the } that variable NO LONGER EXISTS.
    Any data you stored in that array is GONE.

    The nasty part is that the compiler doesn't tell you if there is another variable by the same name that is defined outside of the {}. So you think you are storing in the outer one and that the data will be there when you exit the {}. But its gone.

  5. #5
    Jubic is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Default

    I think I kinda get your meaning, I should move

    Java Code:
    String[][]Hall1 = new String[5][6];
    and the other two similar ones, out of the IF and ELSE IF loops of hallChoice?

  6. #6
    Jubic is offline Member
    Join Date
    May 2010
    Posts
    8
    Rep Power
    0

    Thumbs up Problem Solved.

    Thanks for helping out. Assignment is completed. Greatly appreciated :D

Similar Threads

  1. How to play movie using java
    By sithara in forum New To Java
    Replies: 3
    Last Post: 02-20-2013, 12:29 PM
  2. movie
    By okabeer in forum AWT / Swing
    Replies: 3
    Last Post: 11-17-2011, 12:25 AM
  3. Masking passwords & booking movies
    By suneko in forum New To Java
    Replies: 19
    Last Post: 07-22-2010, 04:46 AM
  4. Replies: 1
    Last Post: 04-27-2010, 11:29 PM
  5. MeD's Movie Manager 2.5.4.1
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-26-2007, 08:29 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •