I know this is a very common program that has been discussed, and I have searched through all the previous posts about it but still having problems. It's a program for an airline seating reservation. Consists of 12 seats total, 1-4 is First Class, and 5-12 is Economy. I have to use a two dimensional array to simulate the seats. I am having trouble with the loop and also on how to work in a boolean expression into the program. I am a beginner to java. Here is what I have so far:

import java.util.Scanner;

public class flight{
  public static void main(String[] args){

      Scanner input = new Scanner(System.in);

  	  boolean seat[][];
  	  seat = new boolean[6][2];

      	int value;
        value = 1;
        while(value != 0)

      System.out.print("Please type 1 for First Class or type 2 for Economy or type 0 to end the program.");
		value = input.nextInt();

      switch (value){
		case 1:

		for (int i = 0; i < 2; i++)
{		
    for (int j = 0; j <2; j++)
    if(i<2 & j<2)
    System.out.println("Your seat is: " + 2*i + (j+i));
}

else {
		System.out.println();
		System.out.print("There are no more seats available in the selected class");
}
		break;

		case 2:

		for (int i = 2; i < 6; i++)
{
   for (int j = 2; j <6; j++)
   if(i<6 & j<6)
System.out.println("Your seat is " + 2*i + (j+i));
}

else {
		System.out.println();
		System.out.print("There are no more seats available in the selected class");
}
		        break;

		case 0:

			break;

		default:
				System.out.println("Invalid selection, please try again..!");

		}
         }
}

and what exactly are you stuck with?
I'm just checking this from work during my lunch, which means I don't have the time to copy-paste-compile-run-debug the entire story.

what do you get? what did you expect to get? what error messages or exceptions do you get?

if we know that, at least we'll now better where to look.

As the above poster said, most of us are sneaking onto this forum at work so we don't have time to work out what your problem is when you can just tell us.

Also, try to format your code in a consistent manner
        it would be
 silly                     if I wrote my
Sentences          like
          this, it makes it
really
                                    hard for people
       to understand.

The problem I am having when I compile and run the program is that its just continuously looping, so it looks like the matrix

The problem I am having when I compile and run the program is that its just continuously looping, so it looks like the matrix

is it really that hard to tell us where it is repeating? What does "so it looks like the matrix" mean?

if it loops on "Please type 1 for First Class or type 2 for Economy or type 0 to end the program." then this is the problem:

while(value != 0)

      System.out.print("Please type 1 for First Class or type 2 for Economy or type 0 to end the program.");

if this is the case, read my post above and format your code properly!!! you may even spot the mistake then:

whie(true)
   System.out.println("one");
   System.out.println("two");

//is not the same as

whie(true)
{
   System.out.println("one");
   System.out.println("two");
}

//if formatted correctly, it should look like this:

whie(true)
   System.out.println("one");

System.out.println("two");

//in the above, you can clearly see that the second print line is not included in the loop

Thats my theory, I don't have time to test it.

Edited 5 Years Ago by hanvyj: n/a

This article has been dead for over six months. Start a new discussion instead.