Reputation: 1
So i'm trying to solve what I thought was a pretty simple program, but it's giving me lots of trouble.
I'm very new to java so my knowledge is limited, but I feel like this is a good learning experience.
So the program requirements are to create an airline program that assigns seats on an airplane.
I must use a 2D boolean array, and make it so when the seats are filled, the array value is set to true.
The user must be able to select between First and Economy Class, and choose either a window or isle seat. A seat cannot be selected twice. Also it asks to display an updated visual representation of the plane seats, and I imagine it is supposed to loop through the program, and then prompt the user to enter in the details for the new customer with the updated visual representation.
Heres the code I have so far, any help would be appreciated.
my issue that i'm having is that I can't figure out how to take the user input for the Class Selection and the Seat selection, and then use that in combination with my for-loops to fill the seats correctly. I also was wondering if the for loops that i used are correct, if the syntax and logic behind it. I'm having troubles getting my thoughts into code.
import java.util.Scanner;
public class AirLinerApp {
boolean SeatArray[][] = new boolean[4][4];
Scanner scan = new Scanner (System.in);
public void MakeReservation()
{
System.out.println("Please type 1 for first class or 2 for economy class: ");
int classinput = scan.nextInt();
System.out.println("Please type 1 for a window seat or 2 for an isle seat: ");
int seatinput = scan.nextInt();
if(classinput == 1 &&seatinput == 1)
{
FirstClassWindow();
}
if(classinput ==1 &&seatinput == 2)
{
FirstClassIsle();
}
if(classinput ==2 &&seatinput == 1)
{
EconomyClassWindow();
}
if(classinput ==2 &&seatinput ==2)
{
EconomyClassIsle();
}
}
public void FirstClassWindow()
{
for(int i=0;i <=1;i++){
if(SeatArray[i][0] == false)
SeatArray[i][0]= true;
if (SeatArray[i][3] == false)
SeatArray[i][3] = true;
}
}
public void FirstClassIsle()
{
for(int i=0;i <=1;i++){
if(SeatArray[i][1] == false)
SeatArray[i][1] = true;
if(SeatArray[i][2] == false)
SeatArray[i][2] = true;
}
}
public void EconomyClassWindow()
{
for(int i=2;i <=3;i++){
if(SeatArray[i][0] == false)
SeatArray[i][0] = true;
if(SeatArray[i][0] == false)
SeatArray[i][0] = true;
}
}
public void EconomyClassIsle()
{
for(int i=2;i <=3;i++){
if(SeatArray[i][1] == false)
SeatArray[i][1] = true;
if(SeatArray[i][2] == false)
SeatArray[i][2] = true;
}
}
public static void SeatDisplay()
{
}
}
Upvotes: 0
Views: 706
Reputation: 61
Well an array of Boolean can hold only one type of information(if seat is taken or not) so what you can do is have two different arrays, one for first class and one for Economy, and based on user choice present one array or the other. another way is to have a an array of all seats, and another of which class a seat is. so if array[1][1] is to be selected, you check array2[1][1] to see if it is first class or not.
Upvotes: 1