forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairline_management_system_demo.py
56 lines (45 loc) · 2.13 KB
/
airline_management_system_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime, timedelta
from typing import List
from airline_management_system import AirlineManagementSystem
from passenger import Passenger
from flight import Flight
from aircraft import Aircraft
from seat import Seat, SeatType
class AirlineManagementSystemDemo:
@staticmethod
def run():
airline_management_system = AirlineManagementSystem()
# Create users
passenger1 = Passenger("U001", "John Doe", "[email protected]", "1234567890")
# Create flights
departure_time1 = datetime.now() + timedelta(days=1)
arrival_time1 = departure_time1 + timedelta(hours=2)
flight1 = Flight("F001", "New York", "London", departure_time1, arrival_time1)
departure_time2 = datetime.now() + timedelta(days=3)
arrival_time2 = departure_time2 + timedelta(hours=5)
flight2 = Flight("F002", "Paris", "Tokyo", departure_time2, arrival_time2)
airline_management_system.add_flight(flight1)
airline_management_system.add_flight(flight2)
# Create aircrafts
aircraft1 = Aircraft("A001", "Boeing 747", 300)
aircraft2 = Aircraft("A002", "Airbus A380", 500)
airline_management_system.add_aircraft(aircraft1)
airline_management_system.add_aircraft(aircraft2)
# Search flights
search_date = datetime.now().date() + timedelta(days=1)
search_results: List[Flight] = airline_management_system.search_flights("New York", "London", search_date)
print("Search Results:")
for flight in search_results:
print(f"Flight: {flight.flight_number} - {flight.source} to {flight.destination}")
seat = Seat("25A", SeatType.ECONOMY)
# Book a flight
booking = airline_management_system.book_flight(flight1, passenger1, seat, 100)
if booking:
print(f"Booking successful. Booking ID: {booking.booking_number}")
else:
print("Booking failed.")
# Cancel a booking
airline_management_system.cancel_booking(booking.booking_number)
print("Booking cancelled.")
if __name__ == "__main__":
AirlineManagementSystemDemo.run()