0

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()
        {

        }


    }
4
  • 1
    You need to provide a specific question within regards to the issue you are having, dumping a bunch of code and a problem statement onto us isn't what StackOverflow is for. Commented Feb 10, 2015 at 2:36
  • @MadProgrammer isn't* not it's Commented Feb 10, 2015 at 2:36
  • Okay, my issue that i'm having is that I can't figure out how to get 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 Commented Feb 10, 2015 at 2:41
  • @cranny Saying "My issue is that I can't <description of entire program here>" doesn't really narrow it down. Commented Feb 10, 2015 at 2:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.