I have create a class called Airline Reservations and I have all my codes by I am having trouble assigning seats in the plane and need some help. Please help.

Recommended Answers

All 5 Replies

post code, ask specific questions, show effort.

I have create a class called Airline Reservations and I have all my codes by I am having trouble assigning seats in the plane and need some help. Please help.

Here's what I have:
class AirlineReservationSystems

import java.util.Arrays;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class AirlineReservationSystems
{
public static void main( String[] args )
{
Scanner input = new Scanner(System.in);

int secondInput;
int element = 0;
int secondElement;
int firstCount = 0;
int economyCount = 0;
int seats[] ={ 0,0,0,0,0,0,0,0,0,0 };


for(int i=0; i<10; i++)
System.out.println(i + " ");
System.out.println(seats[9] + "  ");
String inputa;

inputa = JOptionPane.showInputDialog( "Please type 1 for First Class and Please type 2 for Economy");
int inputb = Integer.parseInt(inputa);
if (inputb == 1 || inputb == 2)
{
Arrays.sort(seats);
	element = Arrays.binarySearch( seats, 0 );
	if (element==-1 && inputb == 1)
		{
	System.out.println("The First Class is already fully booked<br/>");
		}
	else if (element ==-1 && inputb == 2)
		{
		System.out.println("The Economy Class is already fully booked<br/>");
		}
	//to terminate the program
	//else
}
/*if (inputb == 1)
	{
	for (int n=0; n<6 ; n++)
	if (seats[n] == 0)

	else if (inputb == 2)
	{
	for (int n=6; n<10 ; n++)
	if (seats [n] == 0)
{
*/
if (inputb ==1)
{
System.out.println("----------BOARDING PASS----------<br/>");
System.out.println("You are allocated in the First Class<br/>");
System.out.println("Your seat number is ");
System.out.println("-----------------------------------------<br/>");
seats[element]= 1;
firstCount++;
}
else if (inputb ==2)
{
System.out.println("----------BOARDING PASS----------<br/>");
System.out.println ("You are allocated in the Economy Class<br/>");
System.out.println("Your seat number is ");
System.out.println("-----------------------------------------<br/>");
seats[element]= 1;
economyCount++;
}
if (inputb == 1)
{
for (int n=6; n<10 ;n++)
{
if (seats[n] == 0)
{
String secondInputa = JOptionPane.showInputDialog("Do you want to move to Economy Class? (If YES, please press 1. If NO, please press 2)");
secondInput = Integer.parseInt(secondInputa);
if (secondInput == 1 || secondInput == 2)
if ( secondInput == 1)
{

inputb = 2;
element = Arrays.binarySearch( seats, 1 );
System.out.println("You have been allocated to Economy Class<br/>");
break;
}
else if (secondInput == 2)
{
System.out.println("Next flight leaves in 3 hours<br/>");
break;
}
else if (inputb == 2)
{
for (int m=0; n<6 ;n++)
{
if (seats [m] == 0)
{
secondInputa = JOptionPane.showInputDialog("Do you want to move to First Class? (If YES, please press 1. If NO, please press 2)","0");
secondInput = Integer.parseInt(secondInputa);
if ( secondInput == 1)
{
inputb = 1;
element = Arrays.binarySearch( seats, 1 );
System.out.println("You have been allocated to First Class<br/>");
break;
}
}
else if (secondInput == 2)
{
System.out.println("Next flight leaves in 3 hours<br/>");
break;
}
}
}
}
}
}
}
} // end class AirlineReservationSystems

OutOfCodeTagError at line 1, redo from start

I suggest you to have a look on java tutorial which is present on java.sun.com It will help you.

commented: dirty sig spammer -2
commented: F.Y. -2

In general, you should modularize your code so that these things are separate processes:

1. Prompting the user for what type of seat they want
2. Finding an open seat that fits the user's selection from (1)
3. Assigning the user to the open seat
4. Prompting the user for (or with) more information.

Right now you have one big block of code with everything thrown in. Asking passengers for information, finding open seats, and putting passengers in those open seats are all logically different tasks. Therefore, your program should treat them as such. Use methods to separate your code. Once you do that, I will gladly take a more in depth look through your code. Right now, I'm pretty sure you're having so much trouble because everything is in one big jumble, not logically separated into parts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.