Hi folks
I know this particular program has been posted in many other forums but it all involves many different things that I have no learned yet so I really can't use any of them.....plus it would make me look stupid to turn in something that I copied that includes code that is beyond my understanding.....and also pretty obvious as well.
Anyway this is the airplane reservation program involving 2D arrays which seems to be a teacher favorite apparently from all the other forums posts on different web sites. I had thought that I was on the right track with getting this program done and working but apparently I had jumped the gun on that thought process.
Anyways here goes the explanation of what I was attempting to do. The total seats on my reservation 2D should be 80.......20 rows and 4 columns. And I am using a menu system where 1 is First class which is rows 1-3 and then option 2 is rows 4-7 and then option 3 is rows 8-20 all broken into different classes of seating which you will see from my program. And then option 4 will display all available seats.
Now when a customer makes a reservation the program will give them a boarding pass with the row and column and class type. If the class is full it will tell the user and make them enter another seating.....if the entire 80 seats are full it will alert the user and then tell them to take another flight.
Ok so the 2D array needs to be initialized to zero seats taken and then when a seat is taken it needs to set that element to 1 to show that it is taken. It should never be able to assign a seat that is already taken aka double booking lol
Here is my code so far:
import java.util.*;
public class airlineReservation
{
public static final int MAX_COLUMN = 4;
public static final int MAX_ROW = 20;
public static void main(String[] args)
{
int[][] totalSeats = new int[MAX_ROW][MAX_COLUMN];
Scanner input = new Scanner(System.in);
System.out.println("Choose and Option 1-5!");
System.out.println("1. First Class");
System.out.println("2. Business Class");
System.out.println("3. Economy Class");
System.out.println("4. Display All Available Seats!");
System.out.println("5. Quit!");
int menuChoice;
menuChoice = input.nextInt();
switch(menuChoice)
{
case 1:
System.out.println("You have Chosen First Class!");
makeFirstReservation(totalSeats,input);
break;
case 2:
System.out.println("You have Chosen Business Class!");
makeBusinessReservation(totalSeats,input);
break;
case 3:
System.out.println("You have Chosen Economy Class!");
makeEconomyReservation(totalSeats,input);
break;
case 4:
System.out.println("You have Chosen to Display All Available Seating!");
displayArray(totalSeats);
break;
case 5:
System.out.println("You have Chosen to Quit the Program!");
break;
}
}
public static void makeFirstReservation(int[][] totalSeats, Scanner input)
{
for (int row = 0; row < 3; row++)
for (int col = 0; col < 4; col++)
{
row = input.nextInt();
col = input.nextInt();
System.out.println(totalSeats[row][col]);
}
}
public static void makeBusinessReservation(int[][] totalSeats, Scanner input)
{
for (int row = 3; row < 7; row++)
for (int col = 0; col < 4; col++)
totalSeats[row][col] = input.nextInt();
}
public static void makeEconomyReservation(int[][] totalSeats, Scanner input)
{
for (int row = 7; row < 20; row++)
for (int col = 0; col < 4; col++)
totalSeats[row][col] = input.nextInt();
}
/*public static boolean isFirstclassFull(int[][] totalSeats)
{
boolean result;
if (row < 3)
result = true;
else
result = false;
return result;
}
public static boolean isBusinessclassFull(int[][] totalSeats)
{
boolean result;
if ((row > 3)&&(row < 7))
result = true;
else
result = false;
return result;
}
public static boolean isEconomyclassFull(int[][] totalSeats)
{
boolean result;
if ((row > 8)&&(row < 20))
result = true;
else
result = false;
return result;
}*/
public static void displayArray(int[][] totalSeats)
{
for (int row = 0; row < totalSeats.length; row++)
for (int col = 0; col < totalSeats[row].length; col++)
System.out.printf("%7d",totalSeats[row][col]);
System.out.println();
}
}
This program needs to be simple and at my own skill level which I have attempted to do. But I have been deleting and adding things like mad. This program is really frustrating me to no end it seems. MY menu system for instance just keeps asking me over and over to enter numbers lol and when I choose print the array is prints a whole bunch of unorganized characters.
TEAR THIS PROGRAM APART! lol be brutal and let me know what dumb things I am doing wrong and how to do it the right way please.....don't be afraid to totally bash what I have done so far I know my coding skills aren't that great.