Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment will test your skills in object-oriented programming with multip

ID: 3846782 • Letter: T

Question

This assignment will test your skills in object-oriented programming with multiple classes and the use of ArrayLists as the data structure. You are to design a program that implements a basic Airline Booking System (ABS). The ABS allows a client program to create airports, airlines, and flights. Each flight has an originating airport (origin) and a destination airport (destination). The origin and destination cannot be the same. Each flight consists of seats organized in rows. Each row has six seats ("A", "B", "C", "D", "E", "F").

This assignment will test your skills in object-oriented programming with multiple classes and the use of ArrayLists as the data structure. You are to design a program that implements a basic Airline Booking System (ABS). The ABS allow client program to create airports, airlines, and flights. Each flight has an originating airport (origin) and a destination airport (destination). The origin and destination cannot be the same. Each flight consists of seats organized in rows. Each row has six seats ("A", "B", "C", "D", "E", "F). Your program should have the following functionality: 1. Create an airport: An airport must have a name consisting of exactly three alphabetic characters. No two airports can have the same name 2. Create an airline: An airline has a name that must have length less than 6 alphabetic characters. No two airlines can have the same name Create a flight given an airline name, the name ofthe originating airport, the name of a destination airport, and a flight number: A flighthas an identifier that is a string of alphanumeric characters. Create seats for a flight: The number ofrows of seats for this flight is provided. 5. Find available flights: Finds all flights from an originating airport to a destination airport Book a seat: Books an available seat from a given origin to a given destination on a given flight. Print system details: Displays attributes of all objects (e.g., airports, airlines, etc. in the system Your program must have the following classes: System Manager class: This is the main class that aggregates the other classes and provides functionality to the client program. A client program with a main method accesses the System Manager class This class has the following attributes: Airports an arraylist of airport objects, initially empty Airlines an arraylist of airline objects, initially empty Flights an arraylist of flight objects, initially empty. If required, add other attributes. The class has the following methods createAirport(String n): Creates an airport object and updates the appropriate arraylist. The airport will have a name (code) n; n must have exactly three alphabetic characters. No two airports can have the same name. create Airline(String n): Creates an airline object with name n and updates the appropriate arraylist. An airline has a name that must have a length less than 6. No two airlines can have the same name. create Flight(String aname, String orig, String dest, String id): Creates a flight for an airline named aname from an originating airport (orig to a destination airport (dest. The flight has an identifier (id0 create Seats(String air, String flID, int rows Creates seats with the given number of rows for a flight with identifier flID, associated with an airline, air findAvailableFlights(String orig, String dest): Finds all flights from airport orig to airport dest. bookSeat(String air, Stringfl, int row, char col Books seat in given row and column on flight fl of airline f that particular seat is still available display systemDetails0: Displays attribute values for all objects (e.g., airports, flights) in the system 2. Airport class: The only information that is maintained in this class is the name, which must be thre alphabetic characters. Add the appropriate get, set and toString methods 3. Airline class: This class maintains information about airlines. All flights for a given airline must have unique ids Flight class: This class maintains information about flights. Ithas the following attributes: a. Airline b. Flight id c, Seats: An array of Seat objects Add appropriate methods.

Explanation / Answer

//Client.java

public class Client
{
public static void main (String[] args)
{
SystemManager res = new SystemManager();

//create airports
res.createAirport("YHZ");
res.createAirport("R34");//invalid
res.createAirport("bei");
res.createAirport("JFK");
res.createAirport("YYC");
res.createAirport("BEIJING"); //invalid
res.createAirport("123");//invalid
res.createAirport("YEG");

//create airlines
res.createAirline("AC");
res.createAirline("CA");
res.createAirline("HNAIR");
res.createAirline("WSJET");
res.createAirline("FRONTIER"); //invalid

//create flights
res.createFlight("AC", "YHZ", "JFK", "3867");
res.createFlight("CA", "YEG", "YYC", "567");
res.createFlight("HNAIR", "YHZ", "JFK", "3867");
res.createFlight("AC", "YYC", "YHZ", "3867");//invalid. same ID for the same airline
res.createFlight("HNAIR", "YEG", "YEG", "3579");//invalid. Airport is the same
res.createFlight("WSJET", "YHZ", "BOS", "3867");


//find available flights
res.findAvailableFlights("YHZ", "JFK");


//create seats
res.createSeats("AC", "3867", 40);
res.createSeats("HNAIR", "7842", 25);//invalid-7842 not created
res.createSeats("WSJET", "3867", 36);
  

  
//book seats
res.bookSeat("AC", "3867", 15, 'C');
res.bookSeat("AC", "3867", 20, 'N'); //invalid - N doesn't exist
res.bookSeat("WSJET", "2671", 2, 'F'); // invalid - 2671 not created
res.bookSeat("AC", "3867", 78, 'C'); // invalid - row 78 doesn't exist

//display system details
res.displaySystemDetails();
}
}


//Airline.java
public class Airline
{
private String name;
  
//constructor
public Airline(String n)
{
name = n;
}
  
//get and set name
public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
  
public String toString()
{
return "Airline Name: "+name;
}
}

//Airport.java
public class Airport
{
private String name;
  
//constructor
public Airport(String n)
{
name = n;
}
  
//get and set name
public String getName()
{
return name;
}
public void setName(String n)
{
name = n;
}
  
public String toString()
{
return "Airport Name: "+name;
}
}

//Flight.java
public class Flight
{
private String line;
private String id;
private Seat[][] seat;
private String orig, dest;
  
//constructor
public Flight(String l, String id, String o, String d)
{
line = l;
this.id = id;
orig = o;
dest = d;
}
  
//set and get methods
public void setLine(String l)
{
line = l;
}
public void setID(String id)
{
this.id = id;
}
  
public void setOrig(String o)
{
orig = o;
}
public void setDest(String d)
{
dest = d;
}
  
public String getLine()
{
return line;
}
public String getId()
{
return id;
}
public String getOrig()
{
return orig;
}
public String getDest()
{
return dest;
}
public Seat getSeat(int i, int j)
{
return seat[i][j];
}
  
//create seat and book seat
public void createSeat(int row)
{
seat = new Seat[row][6];
  
for (int i = 0; i < row; i++)
for (int j = 0; j < 6; j++)
seat[i][j] = new Seat(i, (char)(j + 65));
}
  
public void bookSeat(int row, char col)
{
if (row > seat.length || col > 70 || col < 65)
System.out.printf("Seat (%d,%c) is invaild. ",row,col);
else{
if(!seat[row-1][(int)col - 65].getStatus())
seat[row-1][(int)col - 65].setStatus();
else
System.out.printf("Seat (%d,%c) has been reserved. ",row,col);
}
}
  
//toString method
public String toString()
{
String seats = "";
if (seat != null){
for (int i = 0; i < seat.length; i++)
for (int j = 0; j < seat[i].length; j++)
if (seat[i][j].getStatus())
seats += seat[i][j].toString()+" ";
}
else
seats = "None";
if (seats.equals(""))
seats = "Not reserved";
return "Airline: "+line+" Flight ID: "+id+" Originating Airport: "+orig+" Destination Airpot: "+dest+" Reserved seat: "+seats;
}
}

//Seat.java

public class Seat
{
private boolean status;
private int row;
private char col;
  
//constructor
public Seat(int r, char c)
{
row = r;
col = c;
status = false;
}
  
//set and get methods
public void setRow(int row)
{
this.row = row;
}
public void setCol(char col)
{
this.col = col;
}
public void setStatus()
{
status = true;
}
  
public int getRow()
{
return row;
}
public char getCol()
{
return col;
}
public boolean getStatus()
{
return status;
}

public String toString()
{
return ""+(row+1)+col;
}
  
}   

//SystemManager.java
import java.util.ArrayList;

public class SystemManager
{
private ArrayList<Airport> airport;
private ArrayList<Airline> airline;
private ArrayList<Flight> flight;

public SystemManager()
{
airport = new ArrayList <Airport>();
airline = new ArrayList <Airline>();
flight = new ArrayList <Flight>();
}
  
//create Airport
public void createAirport(String n)
{
boolean check = true;
String pattern = "[a-zA-Z][a-zA-Z][a-zA-Z]";
if (!n.matches(pattern))//check pattern
System.out.printf("The name of airport %s should be only three alphabetic characters. ", n);
  
else{
if(airport.size() != 0)//check if already been contained
for(int i=0; i<airport.size()&& check; i++)
if(airport.get(i).getName()== n){
System.out.printf("The Airport %s has already been created. ",n);
check = false;
}
if(check)
airport.add(new Airport(n));
}
}
  
//create Airline
public void createAirline(String n)
{
int length = n.length();
boolean check = true;
if (length>=6)//check pattern
System.out.printf("The name of airline %s should have less than 6 characters. ",n);
  
else{
if(airline.size() != 0)//check if already been contained
for(int i=0; i<airline.size()&& check; i++)
if(airline.get(i).getName() == n){
System.out.printf("The Airline %s has already been created. ",n);
check = false;
}
if(check)
airline.add(new Airline(n));

}
}
  
//create flight
public void createFlight(String aname, String orig, String dest, String id)
{
boolean check = true;
if(flight.size() != 0)//check if already been contained
for(int i=0; i<flight.size()&& check; i++)
if(flight.get(i).getId().equals(id) && flight.get(i).getLine().equals(aname)){
System.out.printf("The flight Id %s for Airline %s has already been used. ",id,aname);
check = false;
}
if(orig == dest){
check = false;
System.out.printf("The originating and destination airport %s cannot be the same. ",orig);
}
if(check)
flight.add(new Flight(aname,id,orig,dest));
}
  
//create seat
public void createSeats(String air, String flID, int rows)
{
boolean check = true;
for(int j=0;j<flight.size()&& check;j++)
if(flight.get(j).getId() == flID && flight.get(j).getLine() == air){
flight.get(j).createSeat(rows);
check = false;
}
if (check)//check if the flID is correct
System.out.printf("The flight %s does not exist. ",flID);
}
  
//find flight
public void findAvailableFlights(String orig, String dest)
{
int count=0;
System.out.println(" The flights from " + orig + " to " + dest + ":");
  
for(int i=0; i<flight.size(); i++)
if (flight.get(i).getOrig()== orig && flight.get(i).getDest() == dest){
System.out.println(flight.get(i));
count++;
}
System.out.println();
if(count==0)
System.out.println("No flight is available.");
}
  
//book seat
public void bookSeat(String air, String fl, int row, char col)
{
boolean check = true;
for(int i=0; i<flight.size()&& check; i++)
if (flight.get(i).getLine()== air && flight.get(i).getId() == fl){
flight.get(i).bookSeat(row,col);
check = false;
}
if (check)
System.out.println("The flight does not exist.");
}
  
public void displaySystemDetails()
{
System.out.println(" Airports:");
for (int i = 0; i < airport.size(); i++)
System.out.println(airport.get(i));
System.out.println(" Airlines:");
for (int i = 0; i < airline.size(); i++)
System.out.println(airline.get(i));
System.out.println(" Flights:");
for (int i = 0; i < flight.size(); i++)
System.out.println(flight.get(i));
}
}

/*
output

The name of airport R34 should be only three alphabetic characters.   
The name of airport BEIJING should be only three alphabetic characters.   
The name of airport 123 should be only three alphabetic characters.   
The name of airline FRONTIER should have less than 6 characters.

The flight Id 3867 for Airline AC has already been used.
The originating and destination airport YEG cannot be the same.   
  
The flights from YHZ to JFK:
Airline: AC Flight ID: 3867 Originating Airport: YHZ Destination Airpot: JFK Reserved seat: None
Airline: HNAIR Flight ID: 3867 Originating Airport: YHZ Destination Airpot: JFK Reserved seat: None   
  
The flight 7842 does not exist.   
  
Seat (20,N) is invaild.   
The flight does not exist.
Seat (78,C) is invaild.   
  
Airports:   
Airport Name: YHZ   
Airport Name: bei   
Airport Name: JFK   
Airport Name: YYC   
Airport Name: YEG   
  
Airlines:   
Airline Name: AC
Airline Name: CA
Airline Name: HNAIR   
Airline Name: WSJET   
  
Flights:
Airline: AC Flight ID: 3867 Originating Airport: YHZ Destination Airpot: JFK Reserved seat: 15C   
Airline: CA Flight ID: 567 Originating Airport: YEG Destination Airpot: YYC Reserved seat: None   
Airline: HNAIR Flight ID: 3867 Originating Airport: YHZ Destination Airpot: JFK Reserved seat: None   
Airline: WSJET Flight ID: 3867 Originating Airport: YHZ Destination Airpot: BOS Reserved seat: Not reserved   

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote