public class Flight
{
//instance variables
private String flightNumber;
private String day;
private String destination;
private int freeSeats;
private String error;
// constructors
public Flight()
{
this.flightNumber = " ";
this.day = " ";
this.destination = " ";
this.freeSeats = 0;
}
public Flight(String fNum, String day, String destination, int seatsBooked, int seatSold, int freeSeats)
{
this.flightNumber = fNum;
this.day = day;
this.destination = destination;
this.freeSeats = freeSeats;
}
public String getFlightNumber()
{
return this.flightNumber;
}
public String getDay()
{
return this.day;
}
public String getDestination()
{
return this.destination;
}
public int getFreeSeats()
{
return this.freeSeats;
}
public String flightNumber()
{
if(flightNumber.matches("EL[0-9][0-9][0-9]"))
{
this.flightNumber = flightNumber;
System.out.println("Flight Number Accepted");
return this.flightNumber;
}//end if
else
{
System.out.println("Invalid Number......Flight Number Must Start With EL And Have 3 Digits");
return error;
}//end else
}
public String day()
{
if(day.matches("[Monday][Tuesday][Wednesday][Thursday][Friday][Saturday][Sunday]"))
{
this.day = day;
System.out.println("You Will Be Traveling On " + this.day);
return this.day;
}// end if statement
else
{
System.out.println("Invalid option choosen");
return error;
}
}
public String destination()
{
this.destination = destination;
return this.destination;
}
public int freeSeats(int freeSeats)
{
if(freeSeats < 10 && freeSeats > 0)
{
System.out.println("Seats Available");
return this.freeSeats;
}
else
{
System.out.println("No Seats availabele");
return 0;
}
}
public void display()
{
System.out.println(" Please Enter Flight Number Please: " + this.flightNumber);
System.out.println(" Enter Day Of Departure: " + this.day);
System.out.println(" Enter Destination: " + this.destination);
System.out.println("Number Of avaialable Seats + " + this.freeSeats);
}
}
public class Passenger
{
//instance variables
private String name;
private String address;
private String emailAddress;
private Flight flightBooked;// will hol the adress of the flight object
private String flightValid;
private String answer;
//constructors
public Passenger()
{
this.name = " ";
this.address = " ";
this.emailAddress = " ";
this.flightBooked = null;
}
public Passenger(String name, String address, String emailAddress, Flight flightBooked)
{
this.name = name;
this.address = address;
this.emailAddress = emailAddress;
this.flightBooked = flightBooked;
}
//Getter methods
public String getName()
{
return this.name;
}
public String getAddress()
{
return this.address;
}
public String getEmailAddress()
{
return this.emailAddress;
}
public Flight getFlightBooked()
{
return this.flightBooked;
}
//Setter methods
//Getter methods
public String name()
{
this.name = name;
System.out.println("Please Enter Name");
return this.name;
}
public String address()
{
this.address = address;
System.out.println("Please Enter Address");
return this.address;
}
public String email()
{
this.emailAddress = emailAddress;
System.out.println("Please Enter Email");
return this.emailAddress;
}
public Flight flightBooked()
{
this.flightBooked = flightBooked;
System.out.println("Enter Flight Number");
return this.flightBooked;
}
//create a flight here to store info about the flight!
public boolean flightValid()
{
if(flightValid.equals("Yes"))
{
return true;
}
else
{
return false;
}
}
public void displayP()
{
System.out.println(" Please Enter Name: " + this.name);
System.out.println(" Please Enter ADrress: " + this.address);
System.out.println(" Enter Email: " + this.emailAddress);
System.out.println(" flight Booked?: " + this.flightBooked);
}
}
import java.util.Random;
import java.util.ArrayList;
import java.io.*;
import java.util.Scanner;
public class Booking
{
ArrayList<String> Flight;
ArrayList<String> Passenger;
int numberFlights;
int numberPassengers;
public Booking()
{
Flight = new ArrayList<String>();
Passenger = new ArrayList<String>();
}
public void getNumberFlights()
{
Scanner scan = new Scanner(System.in);
System.out.print("How many flights are there?");
numberFlights = scan.nextInt();
scan.nextLine();
}
public void getNumberpassengers()
{
Scanner scan = new Scanner(System.in);
Passenger passenger;
System.out.print("How many flights are there?");
numberPassengers = scan.nextInt();
scan.nextLine();
}
public void createFlight()
{
//local variables
String flightNumber, day, destination;
Scanner scan = new Scanner(System.in);
Flight anflight;
for (int i = 0; i < numberFlights; i++)
{
System.out.println(" Input Details for flights " + (i + 1));
System.out.println("Enter flight number : ");
flightNumber = scan.nextLine();
System.out.print("Enter Day : ");
day = scan.nextLine();
System.out.print(" Destination: ");
destination = scan.nextLine();
scan.nextLine();
//create new accounds
anflight = new Flight(flightNumber, day, destination);
Flight.add(anFlight);
}//end for
}
public void createPassenger()
{
String name, address, emailAddress, flightBooked;
Scanner scan = new Scanner(System.in);
Passenger anPassenger;
for (int i = 0; i < numberPassengers; i++)
{
System.out.println(" Input Details " + (i + 1));
System.out.println("Enter Name: ");
name = scan.nextLine();
System.out.print("Enter Your Address : ");
address = scan.nextLine();
System.out.print(" Enter Your E-Mail Address: ");
emailAddress = scan.nextLine();
scan.nextLine();
}//end for
}//create passengers
public void menu()
{
Scanner scan = new Scanner(System.in);
System.out.println("****************************");
System.out.println(" Welcome to the Bookings ");
System.out.println(" ");
System.out.println(" Please choose the following");
System.out.println(" 1. Make a booking ");
System.out.println(" 2. cancel Booking ");
System.out.println(" 3. Display full flight info");
System.out.println(" 4. Display Passenger info ");
System.out.println(" 5. Exit system ");
System.out.println("****************************");
}
public void addPerson(String name)
{
Flight.add(name);
}
public void displayF()//method to display those within the flight
{
for (String person : Flight)
{
System.out.println(Flight);
}
}
public void displayP()//method to display those within the Passenger
{
for (String person : Passenger)
{
System.out.println(Passenger);
}
}
public void losePerson()
{
Random generator = new Random();//declares the random generator(instance variable)
int loserIndex = generator.nextInt(5);//next int 3 will cause the generator to create the integers(0,1,2)
String loser = Flight.remove(loserIndex);//this removes a random index int
System.out.println(loser + " Has Cancelled his flight");
}
public static void main(String[] args)
{
Booking booking = new Booking();
Scanner scan = new Scanner(System.in);
int option = 0;
while (!(option == 5))// STarting while to ask for more information again and again.....
{
booking.menu();
System.out.print("Please enter the request :");
option = scan.nextInt();
scan.nextLine();
while (option > 5 || option <= 0)
{
System.out.print("Problem...!! :");
option = scan.nextInt();
scan.nextLine();
}//end while
switch(option)
{
case 1: System.out.println("Making booking: ");
String name = " ";
name = scan.nextLine();
booking.addPerson(name);
break;
case 2 :booking.losePerson();
break;
case 3 :booking.displayFlight();
break;
case 4 :booking.displayPassenger();
break;
case 5 :System.out.println("GoodBye!");
break;
}
}//while ends here
}
{
//instance variables
private String flightNumber;
private String day;
private String destination;
private int freeSeats;
private String error;
// constructors
public Flight()
{
this.flightNumber = " ";
this.day = " ";
this.destination = " ";
this.freeSeats = 0;
}
public Flight(String fNum, String day, String destination, int seatsBooked, int seatSold, int freeSeats)
{
this.flightNumber = fNum;
this.day = day;
this.destination = destination;
this.freeSeats = freeSeats;
}
public String getFlightNumber()
{
return this.flightNumber;
}
public String getDay()
{
return this.day;
}
public String getDestination()
{
return this.destination;
}
public int getFreeSeats()
{
return this.freeSeats;
}
public String flightNumber()
{
if(flightNumber.matches("EL[0-9][0-9][0-9]"))
{
this.flightNumber = flightNumber;
System.out.println("Flight Number Accepted");
return this.flightNumber;
}//end if
else
{
System.out.println("Invalid Number......Flight Number Must Start With EL And Have 3 Digits");
return error;
}//end else
}
public String day()
{
if(day.matches("[Monday][Tuesday][Wednesday][Thursday][Friday][Saturday][Sunday]"))
{
this.day = day;
System.out.println("You Will Be Traveling On " + this.day);
return this.day;
}// end if statement
else
{
System.out.println("Invalid option choosen");
return error;
}
}
public String destination()
{
this.destination = destination;
return this.destination;
}
public int freeSeats(int freeSeats)
{
if(freeSeats < 10 && freeSeats > 0)
{
System.out.println("Seats Available");
return this.freeSeats;
}
else
{
System.out.println("No Seats availabele");
return 0;
}
}
public void display()
{
System.out.println(" Please Enter Flight Number Please: " + this.flightNumber);
System.out.println(" Enter Day Of Departure: " + this.day);
System.out.println(" Enter Destination: " + this.destination);
System.out.println("Number Of avaialable Seats + " + this.freeSeats);
}
}
public class Passenger
{
//instance variables
private String name;
private String address;
private String emailAddress;
private Flight flightBooked;// will hol the adress of the flight object
private String flightValid;
private String answer;
//constructors
public Passenger()
{
this.name = " ";
this.address = " ";
this.emailAddress = " ";
this.flightBooked = null;
}
public Passenger(String name, String address, String emailAddress, Flight flightBooked)
{
this.name = name;
this.address = address;
this.emailAddress = emailAddress;
this.flightBooked = flightBooked;
}
//Getter methods
public String getName()
{
return this.name;
}
public String getAddress()
{
return this.address;
}
public String getEmailAddress()
{
return this.emailAddress;
}
public Flight getFlightBooked()
{
return this.flightBooked;
}
//Setter methods
//Getter methods
public String name()
{
this.name = name;
System.out.println("Please Enter Name");
return this.name;
}
public String address()
{
this.address = address;
System.out.println("Please Enter Address");
return this.address;
}
public String email()
{
this.emailAddress = emailAddress;
System.out.println("Please Enter Email");
return this.emailAddress;
}
public Flight flightBooked()
{
this.flightBooked = flightBooked;
System.out.println("Enter Flight Number");
return this.flightBooked;
}
//create a flight here to store info about the flight!
public boolean flightValid()
{
if(flightValid.equals("Yes"))
{
return true;
}
else
{
return false;
}
}
public void displayP()
{
System.out.println(" Please Enter Name: " + this.name);
System.out.println(" Please Enter ADrress: " + this.address);
System.out.println(" Enter Email: " + this.emailAddress);
System.out.println(" flight Booked?: " + this.flightBooked);
}
}
import java.util.Random;
import java.util.ArrayList;
import java.io.*;
import java.util.Scanner;
public class Booking
{
ArrayList<String> Flight;
ArrayList<String> Passenger;
int numberFlights;
int numberPassengers;
public Booking()
{
Flight = new ArrayList<String>();
Passenger = new ArrayList<String>();
}
public void getNumberFlights()
{
Scanner scan = new Scanner(System.in);
System.out.print("How many flights are there?");
numberFlights = scan.nextInt();
scan.nextLine();
}
public void getNumberpassengers()
{
Scanner scan = new Scanner(System.in);
Passenger passenger;
System.out.print("How many flights are there?");
numberPassengers = scan.nextInt();
scan.nextLine();
}
public void createFlight()
{
//local variables
String flightNumber, day, destination;
Scanner scan = new Scanner(System.in);
Flight anflight;
for (int i = 0; i < numberFlights; i++)
{
System.out.println(" Input Details for flights " + (i + 1));
System.out.println("Enter flight number : ");
flightNumber = scan.nextLine();
System.out.print("Enter Day : ");
day = scan.nextLine();
System.out.print(" Destination: ");
destination = scan.nextLine();
scan.nextLine();
//create new accounds
anflight = new Flight(flightNumber, day, destination);
Flight.add(anFlight);
}//end for
}
public void createPassenger()
{
String name, address, emailAddress, flightBooked;
Scanner scan = new Scanner(System.in);
Passenger anPassenger;
for (int i = 0; i < numberPassengers; i++)
{
System.out.println(" Input Details " + (i + 1));
System.out.println("Enter Name: ");
name = scan.nextLine();
System.out.print("Enter Your Address : ");
address = scan.nextLine();
System.out.print(" Enter Your E-Mail Address: ");
emailAddress = scan.nextLine();
scan.nextLine();
}//end for
}//create passengers
public void menu()
{
Scanner scan = new Scanner(System.in);
System.out.println("****************************");
System.out.println(" Welcome to the Bookings ");
System.out.println(" ");
System.out.println(" Please choose the following");
System.out.println(" 1. Make a booking ");
System.out.println(" 2. cancel Booking ");
System.out.println(" 3. Display full flight info");
System.out.println(" 4. Display Passenger info ");
System.out.println(" 5. Exit system ");
System.out.println("****************************");
}
public void addPerson(String name)
{
Flight.add(name);
}
public void displayF()//method to display those within the flight
{
for (String person : Flight)
{
System.out.println(Flight);
}
}
public void displayP()//method to display those within the Passenger
{
for (String person : Passenger)
{
System.out.println(Passenger);
}
}
public void losePerson()
{
Random generator = new Random();//declares the random generator(instance variable)
int loserIndex = generator.nextInt(5);//next int 3 will cause the generator to create the integers(0,1,2)
String loser = Flight.remove(loserIndex);//this removes a random index int
System.out.println(loser + " Has Cancelled his flight");
}
public static void main(String[] args)
{
Booking booking = new Booking();
Scanner scan = new Scanner(System.in);
int option = 0;
while (!(option == 5))// STarting while to ask for more information again and again.....
{
booking.menu();
System.out.print("Please enter the request :");
option = scan.nextInt();
scan.nextLine();
while (option > 5 || option <= 0)
{
System.out.print("Problem...!! :");
option = scan.nextInt();
scan.nextLine();
}//end while
switch(option)
{
case 1: System.out.println("Making booking: ");
String name = " ";
name = scan.nextLine();
booking.addPerson(name);
break;
case 2 :booking.losePerson();
break;
case 3 :booking.displayFlight();
break;
case 4 :booking.displayPassenger();
break;
case 5 :System.out.println("GoodBye!");
break;
}
}//while ends here
}