1 Replies - 2366 Views - Last Post: 03 February 2010 - 09:50 AM Rate Topic: -----

#1 Rania_13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-January 10

Seat reservation using JAVA

Posted 03 February 2010 - 08:13 AM

this is a simple program of seat reservation. As the program prompt for the seat desired, the user can type in a seat and later display the updated seats. this process will continue until the user decide to stop using the program or all seats are filled. I'm using Eclipse to develop this and I dont understand why there's a syntax errors on both "case 2" and "default". Please help.


=====================================================================

import java.util.Scanner;

public class seat_reservation{

public static void main(String[] args) {

// Initialization
final int ROWS = 2;
final int COLS =3;
char [][] seats = new char [ROWS][COLS];
int i, j, seatNum, counter=0;
char seatLetter = 'A';
int choice=0;
String seatEnter;
boolean cont = true; // loops of running the program

Scanner input = new Scanner(System.in);// declare and create variable input as scanner

while(choice!=4){
System.out.print("1. Assign Seats");
System.out.print("2. Exit");
System.out.print("Select your choice: ");

choice=input.nextInt();

switch(choice){
case 1:
}
//Set the value.
for (i=0; i < seats.length; i++) {
for (j=0; j < seats[i].length; j++)
seats[i][j] = seatLetter++;
seatLetter = 'A'; // to reset the value to A for the new loop
}


//To display the list of seats
for (i=0; i < seats.length; i++) {
System.out.print((i+1)+" ");
for (j=0; j < seats[i].length; j++)
System.out.print(seats[i][j]+" ");
System.out.println();
}

//condition
while (counter < 6 && cont) {
do{
System.out.print("Please type the chosen seat(starts with row and column,e.g:2A):" +
"");

seatEnter = (input.nextLine()).toUpperCase(); //covert to Upper case
seatNum = Integer.parseInt(seatEnter.charAt(0)+"");
if (seatNum != 0)
seatLetter = seatEnter.charAt(1);
i++;

//if user enters wrong input, error message will appear.
if (seatLetter!='A'){
if (seatLetter!='B'){
if(seatLetter!='C'){
if(seatLetter!='D')
System.out.println ("Invalid! Please enter the correct seat:");
}
}
}



}
//continue to loop until the condition true
while (seatNum < 0 || seatNum > 7 || seatLetter < 'A' || seatLetter > 'D');

if (seatNum == 0) {
cont = false;
}
else {
if (seats[seatNum-1][seatLetter-65] == 'X')
System.out.println("Seat have been taken.Please choose another seat:");
else {
seats[seatNum -1][seatLetter-65] = 'X';
counter++;


}

// To display updated lists of seats
for (i=0; i < seats.length; i++) {
System.out.print((i+1)+" ");
for (j=0; j < seats[i].length; j++)
System.out.print(seats[i][j] + " ");
System.out.println();
}
System.out.println(" ") ;
//}
//}

// displays fully booked message
// if (counter == 6)
// System.out.println("All seats are now fully-booked.");


break;

case 2://syntax error here

if (counter == 6)
System.out.println("All seats are now fully-booked.");
System.out.println("End of Program");
System.exit(0);

break;

default: System.out.println("Error input"); break;//syntax error here as well.

}

}

Attached File(s)


This post has been edited by Rania_13: 03 February 2010 - 08:27 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Seat reservation using JAVA

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Seat reservation using JAVA

Posted 03 February 2010 - 09:50 AM

please post your code between code tags.

anyway, i glanced at your code and noticed an unnecessary brackets:
switch(choice){
case 1:
}//<<<<<<<<<< this bracket


just remove that bracket. you dont need a closing bracket there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1