Try Our Course for 4 Hours @99rs

Try our course for 4 Hours and if you like it, you can go for one year or lifetime access. If you buy our (1yr or lifetime) course 99rs will be refunded !

Design an Airline Management System - Machine Coding

Design an Airline Management System - Machine Coding

airbus-4454338_1280.webp

Airline Management System

An Airline Management System is a managerial software which targets to control all operations of an airline. Airlines provide transport services for their passengers. They carry or hire aircraft for this purpose. All operations of an airline company are controlled by their airline management system.

This system involves the scheduling of flights, air ticket reservations, flight cancellations, customer support, and staff management. Daily flights updates can also be retrieved by using the system.

Features

We will focus on the following set of requirements while designing the Airline Management System:

  1. Customers should be able to search for flights for a given date and source/destination airport.

  2. Customers should be able to reserve a ticket for any scheduled flight. Customers can also build a multi-flight itinerary.

  3. Users of the system can check flight schedules, their departure time, available seats, arrival time, and other flight details.

  4. Customers can make reservations for multiple passengers under one itinerary.

  5. Only the admin of the system can add new aircrafts, flights, and flight schedules. Admin can cancel any pre-scheduled flight (all stakeholders will be notified).

  6. Customers can cancel their reservation and itinerary.

  7. The system should be able to handle the assignment of pilots and crew members to flights.

  8. The system should be able to handle payments for reservations.

  9. The system should be able to send notifications to customers whenever a reservation is made/modified or there is an update for their flights.

Rough Solution (LLD-Machine Coding)

// Enum classes remain the same
public enum FlightStatus {
    ACTIVE, SCHEDULED, DELAYED, DEPARTED, LANDED, IN_AIR, ARRIVED, CANCELLED, DIVERTED, UNKNOWN
}

public enum PaymentStatus {
    UNPAID, PENDING, COMPLETED, FILLED, DECLINED, CANCELLED, ABANDONED, SETTLING, SETTLED, REFUNDED
}

public enum ReservationStatus {
    REQUESTED, PENDING, CONFIRMED, CHECKED_IN, CANCELLED, ABANDONED
}

public enum SeatClass {
    ECONOMY, ECONOMY_PLUS, PREFERRED_ECONOMY, BUSINESS, FIRST_CLASS
}

public enum SeatType {
    REGULAR, ACCESSIBLE, EMERGENCY_EXIT, EXTRA_LEG_ROOM
}

public enum AccountStatus {
    ACTIVE, CLOSED, CANCELED, BLACKLISTED, BLOCKED
}

// Supporting classes
public class Address {
    private String streetAddress;
    private String city;
    private String state;
    private String zipCode;
    private String country;
}

// Observer Pattern for Notifications
interface Observer {
    void update(String message);
}

class Customer extends Person implements Observer {
    private String frequentFlyerNumber;
    private List<Itinerary> itineraries;

    public Customer(String name, Account account) {
        super(name, account);
        itineraries = new ArrayList<>();
    }

    @Override
    public void update(String message) {
        System.out.println("Notification for Customer: " + getName() + ": " + message);
    }

    public List<Itinerary> getItineraries() {
        return itineraries;
    }
}

// System Notifier using Observer Pattern
class SystemNotifier {
    private List<Observer> observers = new ArrayList<>();

    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    public void notifyObservers(String message) {
        for (Observer observer : observers) {
            observer.update(message);
        }
    }
}

// Abstract Person class
public abstract class Person {
    private String name;
    private Address address;
    private String email;
    private String phone;
    private Account account;

    public Person(String name, Account account) {
        this.name = name;
        this.account = account;
    }

    public String getName() {
        return name;
    }
}

// Factory Method Pattern for Flight-related objects
abstract class ReservationFactory {
    public abstract FlightReservation createReservation(FlightInstance flight, Map<Passenger, FlightSeat> seatMap);
}

class RegularReservationFactory extends ReservationFactory {
    @Override
    public FlightReservation createReservation(FlightInstance flight, Map<Passenger, FlightSeat> seatMap) {
        return new FlightReservation(flight, seatMap);
    }
}

// Command Pattern for reservations and payments
interface Command {
    void execute();
}

class CreateReservationCommand implements Command {
    private FrontDeskOfficer officer;
    private FlightReservation reservation;

    public CreateReservationCommand(FrontDeskOfficer officer, FlightReservation reservation) {
        this.officer = officer;
        this.reservation = reservation;
    }

    @Override
    public void execute() {
        officer.reserveTicket(reservation);
    }
}

class CancelReservationCommand implements Command {
    private FlightReservation reservation;

    public CancelReservationCommand(FlightReservation reservation) {
        this.reservation = reservation;
    }

    @Override
    public void execute() {
        reservation.cancel();
    }
}

class MakePaymentCommand implements Command {
    private Payment payment;
    private Itinerary itinerary;

    public MakePaymentCommand(Payment payment, Itinerary itinerary) {
        this.payment = payment;
        this.itinerary = itinerary;
    }

    @Override
    public void execute() {
        itinerary.makePayment(payment);
    }
}

// Strategy Pattern for Payment
interface PaymentStrategy {
    void pay(Payment payment);
}

class CreditCardPaymentStrategy implements PaymentStrategy {
    @Override
    public void pay(Payment payment) {
        System.out.println("Processing credit card payment...");
        payment.processPayment();
    }
}

class DebitCardPaymentStrategy implements PaymentStrategy {
    @Override
    public void pay(Payment payment) {
        System.out.println("Processing debit card payment...");
        payment.processPayment();
    }
}

// Template Method Pattern for Payment Processing
abstract class Payment {
    protected double amount;
    protected PaymentStatus status;

    public final void processPayment() {
        initiatePayment();
        confirmPayment();
        updatePaymentStatus();
    }

    protected abstract void initiatePayment();

    private void confirmPayment() {
        System.out.println("Payment confirmed.");
    }

    private void updatePaymentStatus() {
        this.status = PaymentStatus.COMPLETED;
        System.out.println("Payment status updated to COMPLETED.");
    }
}

class CreditCardPayment extends Payment {
    @Override
    protected void initiatePayment() {
        System.out.println("Processing credit card payment of amount: " + amount);
    }
}

class DebitCardPayment extends Payment {
    @Override
    protected void initiatePayment() {
        System.out.println("Processing debit card payment of amount: " + amount);
    }
}

// Flight-related classes
public class FlightReservation {
    private String reservationNumber;
    private FlightInstance flight;
    private Map<Passenger, FlightSeat> seatMap;
    private Date creationDate;
    private ReservationStatus status;

    public FlightReservation(FlightInstance flight, Map<Passenger, FlightSeat> seatMap) {
        this.flight = flight;
        this.seatMap = seatMap;
        this.status = ReservationStatus.REQUESTED;
    }

    public boolean cancel() {
        this.status = ReservationStatus.CANCELLED;
        System.out.println("Reservation has been canceled.");
        return true;
    }

    public boolean confirm() {
        this.status = ReservationStatus.CONFIRMED;
        System.out.println("Reservation confirmed.");
        return true;
    }
}

public class FlightInstance {
    private Date departureTime;
    private String gate;
    private FlightStatus status;
    private Aircraft aircraft;

    public FlightInstance(Date departureTime, String gate, Aircraft aircraft) {
        this.departureTime = departureTime;
        this.gate = gate;
        this.aircraft = aircraft;
        this.status = FlightStatus.SCHEDULED;
    }

    public void updateStatus(FlightStatus status) {
        this.status = status;
        System.out.println("Flight status updated to: " + status);
    }
}

public class Aircraft {
    private String name;
    private String model;
    private int manufacturingYear;
    private List<Seat> seats;

    public Aircraft(String name, String model, int year) {
        this.name = name;
        this.model = model;
        this.manufacturingYear = year;
        seats = new ArrayList<>();
    }
}

public class Passenger {
    private String name;
    private String passportNumber;
    private Date dateOfBirth;

    public String getPassportNumber() {
        return passportNumber;
    }
}

public class Seat {
    private String seatNumber;
    private SeatType type;
    private SeatClass seatClass;

    public Seat(String seatNumber, SeatType type, SeatClass seatClass) {
        this.seatNumber = seatNumber;
        this.type = type;
        this.seatClass = seatClass;
    }
}

public class FlightSeat extends Seat {
    private double fare;

    public FlightSeat(String seatNumber, SeatType type, SeatClass seatClass, double fare) {
        super(seatNumber, type, seatClass);
        this.fare = fare;
    }

    public double getFare() {
        return fare;
    }
}

public class Itinerary {
    private String customerId;
    private Airport startingAirport;
    private Airport finalAirport;
    private Date creationDate;
    private List<FlightReservation> reservations;

    public Itinerary() {
        reservations = new ArrayList<>();
    }

    public boolean makeReservation(FlightReservation reservation) {
        reservations.add(reservation);
        System.out.println("Reservation added to itinerary.");
        return true;
    }

    public boolean makePayment(Payment payment) {
        payment.processPayment();
        return true;
    }

    public List<FlightReservation> getReservations() {
        return reservations;
    }
}

public class FrontDeskOfficer extends Person {
    public FrontDeskOfficer(String name, Account account) {
        super(name, account);
    }

    public boolean reserveTicket(FlightReservation reservation) {
        System.out.println("Ticket reserved for flight.");
        return true;
    }

    public boolean cancelTicket(FlightReservation reservation) {
        reservation.cancel();
        System.out.println("Ticket canceled.");
        return true;
    }
}

public class Admin extends Person {
    public Admin(String name, Account account) {
        super(name, account);
    }

    public boolean addFlight(Flight flight) {
        System.out.println("Flight added: " + flight);
        return true;
    }

    public boolean cancelFlight(FlightInstance flight) {
        flight.updateStatus(FlightStatus.CANCELLED);
        System.out.println("Flight canceled.");
        return true;
    }
}

// Airport, Flight, and other classes
// Supporting classes for address and flight details
public class Airport {
    private String name;
    private Address address;
    private String code;
    private List<Flight> flights;

    public Airport(String name, Address address, String code) {
        this.name = name;
        this.address = address;
        this.code = code;
        flights = new ArrayList<>();
    }

    public String getName() {
        return name;
    }

    public Address getAddress() {
        return address;
    }

    public String getCode() {
        return code;
    }

    public List<Flight> getFlights() {
        return flights;
    }

    public void addFlight(Flight flight) {
        flights.add(flight);
        System.out.println("Flight added to airport: " + flight.getFlightNumber());
    }
}

// Flight class representing a flight with schedules and instances
public class Flight {
    private String flightNumber;
    private Airport departure;
    private Airport arrival;
    private int durationInMinutes;
    private List<WeeklySchedule> weeklySchedules;
    private List<CustomSchedule> customSchedules;
    private List<FlightInstance> flightInstances;

    public Flight(String flightNumber, Airport departure, Airport arrival, int durationInMinutes) {
        this.flightNumber = flightNumber;
        this.departure = departure;
        this.arrival = arrival;
        this.durationInMinutes = durationInMinutes;
        this.weeklySchedules = new ArrayList<>();
        this.customSchedules = new ArrayList<>();
        this.flightInstances = new ArrayList<>();
    }

    public String getFlightNumber() {
        return flightNumber;
    }

    public Airport getDeparture() {
        return departure;
    }

    public Airport getArrival() {
        return arrival;
    }

    public int getDurationInMinutes() {
        return durationInMinutes;
    }

    public void addWeeklySchedule(WeeklySchedule schedule) {
        weeklySchedules.add(schedule);
        System.out.println("Weekly schedule added to flight: " + flightNumber);
    }

    public void addCustomSchedule(CustomSchedule schedule) {
        customSchedules.add(schedule);
        System.out.println("Custom schedule added to flight: " + flightNumber);
    }

    public void addFlightInstance(FlightInstance flightInstance) {
        flightInstances.add(flightInstance);
        System.out.println("Flight instance added: " + flightInstance.getGate() + " for flight: " + flightNumber);
    }

    public List<FlightInstance> getFlightInstances() {
        return flightInstances;
    }
}

// FlightInstance class representing individual flight instances with departure time, gate, and status
public class FlightInstance {
    private Date departureTime;
    private String gate;
    private FlightStatus status;
    private Aircraft aircraft;

    public FlightInstance(Date departureTime, String gate, Aircraft aircraft) {
        this.departureTime = departureTime;
        this.gate = gate;
        this.aircraft = aircraft;
        this.status = FlightStatus.SCHEDULED;
    }

    public Date getDepartureTime() {
        return departureTime;
    }

    public String getGate() {
        return gate;
    }

    public FlightStatus getStatus() {
        return status;
    }

    public void updateStatus(FlightStatus status) {
        this.status = status;
        System.out.println("Flight status updated to: " + status);
    }

    public Aircraft getAircraft() {
        return aircraft;
    }

    public boolean cancel() {
        this.status = FlightStatus.CANCELLED;
        System.out.println("Flight instance canceled.");
        return true;
    }
}

// WeeklySchedule for scheduling weekly flights
public class WeeklySchedule {
    private int dayOfWeek;
    private Time departureTime;

    public WeeklySchedule(int dayOfWeek, Time departureTime) {
        this.dayOfWeek = dayOfWeek;
        this.departureTime = departureTime;
    }

    public int getDayOfWeek() {
        return dayOfWeek;
    }

    public Time getDepartureTime() {
        return departureTime;
    }
}

// CustomSchedule for scheduling flights on custom dates
public class CustomSchedule {
    private Date customDate;
    private Time departureTime;

    public CustomSchedule(Date customDate, Time departureTime) {
        this.customDate = customDate;
        this.departureTime = departureTime;
    }

    public Date getCustomDate() {
        return customDate;
    }

    public Time getDepartureTime() {
        return departureTime;
    }
}

// Aircraft class representing the aircraft with seats
public class Aircraft {
    private String name;
    private String model;
    private int manufacturingYear;
    private List<Seat> seats;

    public Aircraft(String name, String model, int manufacturingYear) {
        this.name = name;
        this.model = model;
        this.manufacturingYear = manufacturingYear;
        this.seats = new ArrayList<>();
    }

    public String getName() {
        return name;
    }

    public String getModel() {
        return model;
    }

    public int getManufacturingYear() {
        return manufacturingYear;
    }

    public List<Seat> getSeats() {
        return seats;
    }

    public void addSeat(Seat seat) {
        seats.add(seat);
        System.out.println("Seat " + seat.getSeatNumber() + " added to aircraft: " + name);
    }
}

// Seat class representing seats in an aircraft
public class Seat {
    private String seatNumber;
    private SeatType type;
    private SeatClass seatClass;

    public Seat(String seatNumber, SeatType type, SeatClass seatClass) {
        this.seatNumber = seatNumber;
        this.type = type;
        this.seatClass = seatClass;
    }

    public String getSeatNumber() {
        return seatNumber;
    }

    public SeatType getType() {
        return type;
    }

    public SeatClass getSeatClass() {
        return seatClass;
    }
}

// FlightSeat class extending Seat to include fare details
public class FlightSeat extends Seat {
    private double fare;

    public FlightSeat(String seatNumber, SeatType type, SeatClass seatClass, double fare) {
        super(seatNumber, type, seatClass);
        this.fare = fare;
    }

    public double getFare() {
        return fare;
    }
}

// Passenger class representing the passenger details
public class Passenger {
    private String name;
    private String passportNumber;
    private Date dateOfBirth;

    public Passenger(String name, String passportNumber, Date dateOfBirth) {
        this.name = name;
        this.passportNumber = passportNumber;
        this.dateOfBirth = dateOfBirth;
    }

    public String getName() {
        return name;
    }

    public String getPassportNumber() {
        return passportNumber;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }
}

// Main class to demonstrate design
public class Main {
    public static void main(String[] args) {
        // Create an Admin
        Account adminAccount = new Account();
        Admin admin = new Admin("John Doe", adminAccount);

        // Create a flight and flight instance
        Aircraft aircraft = new Aircraft("Boeing 777", "777-300", 2010);
        FlightInstance flightInstance = new FlightInstance(new Date(), "A12", aircraft);

        // Create a flight reservation using Factory Method
        ReservationFactory reservationFactory = new RegularReservationFactory();
        Map<Passenger, FlightSeat> seatMap = new HashMap<>();
        FlightReservation reservation = reservationFactory.createReservation(flightInstance, seatMap);

        // Front Desk Officer handles reservation using Command Pattern
        FrontDeskOfficer officer = new FrontDeskOfficer("Jane Doe", new Account());
        Command reserveCommand = new CreateReservationCommand(officer, reservation);
        reserveCommand.execute();

        // Process payment using Template Method Pattern
        Payment payment = new CreditCardPayment();
        payment.processPayment();

        // Notify customers using Observer Pattern
        SystemNotifier notifier = new SystemNotifier();
        Customer customer = new Customer("Alice", new Account());
        notifier.addObserver(customer);
        notifier.notifyObservers("Your flight has been scheduled.");
    }
}