Hi everyone .. so i'm creating this project for college it's a system for airplane reservation
i'm using multi dimensional array of objects i have two classes ticket and passenger ..
this is the main
/**
* Name = Rami sohail Mohammed Jamous
* ID = 1324057
* Java 203 Project 2
* Section : AA
* project KAUairBookingSystem
* 02/11/2012
*/
package kauairbookingsystem;
import java.util.Scanner;
public class KAUairBookingSystem {
public static void bookfirstclass(Ticket[][] tc,Scanner input,double ff)
{
System.out.println("How many tickets would you like in First Class:");
int seat = input.nextInt();
System.out.println("You must now enter the passenger information for each ticket/seat");
int psngrnumber = 1;
for(int i = 0;i<2;i++)
{
for(int j = 0;j<7;j++)
{
if (tc[i][j] == null)
{
System.out.println("\nPersonal Data for Passenger #" + psngrnumber++ );
System.out.print("Enter the First Name : ") ;
String fname = input.next();
System.out.print("Enter the last Name : ");
String lname = input.next();
System.out.print("Enter the ID number : ");
int id = input.nextInt();
Passenger psn = new Passenger();
psn.setfname(fname);
psn.setlname(lname);
psn.setid(id);
tc[i][j] = new Ticket();
seat--;
System.out.print(fname + " " + lname + " is Confirmed with Ticket #Kau" + tc[i][j].getTicketNumber());
System.out.print("");
if(seat == 0)
{
i = 2;
j = 7;
}
}
else
{
System.out.println("No Seats Available " + seat + " Seats Couldn't be reserved.");
}
}
}
}
public static void ShowMenu()
{
System.out.println("Welcome To The KAU Air --- Seat Reservation System");
System.out.println("-------------------------------------------\n" +
"1. Book First Class Seats\n" +
"2. Book Buisness Class Seats\n" +
"3. Book Economy Class Seats\n" +
"4. View Air Plane Seating assignment\n" +
"5. View Passenger list\n" +
"6. System Status\n" +
"7. Know Fair\n" +
"8. System Reset\n" +
"9. Exit From The Booking System\n\n" +
"Enter Your Choice :" );
}
public static void displayseats(Ticket[][] tc)
{
System.out.println("\nView Air Plane Seating Assignment");
System.out.println("-------------------------------------------");
for(int i=0;i<tc.length;i++)
{
for(int j=0;j<tc[i].length;j++)
{
if(tc[i][j] == null)
{
System.out.print(0 + " ");
}
else
{
System.out.print(1 + " ");
}
}
System.out.println();
}
System.out.println("-------------------------------------------\n");
}
public static void main(String[] args)
{
Ticket [][] tc = new Ticket[12][7];
while(true)
{
ShowMenu();
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
if(choice == 1)
{
bookfirstclass(tc,input,100);
displayseats(tc);
}
if(choice == 2)
{
}
if(choice == 3)
{
}
if(choice == 4)
{
displayseats(tc);
}
if(choice == 5)
{
}
if(choice == 6)
{
}
if(choice == 7)
{
}
if(choice == 8)
{
}
if(choice == 9)
{
}
}
}}
my problem is with the bookfirstclass method
i want the if condition to check how many seats available and the entered number of seats if the emty seats are not enough it prints an error message but now it just keep on reserving seats whether it's full or not ..