Question: class AirlineReservationSystem: def _ _ init _ _ ( self ) : self.firstClassSeats = [ [ ' ' for _ in range ( 4 )

class AirlineReservationSystem:
def __init__(self):
self.firstClassSeats =[['' for _ in range(4)] for _ in range(2)] # 2 rows, 4 seats each
self.coachClassSeats =[['' for _ in range(10)] for _ in range(4)] # 4 rows, 10 seats each
self.firstClassPrice =500
self.coachClassPrice =199
self.taxRate =0.09 # 9% sales tax
def make_reservation(self, class_type, row, seat, name, age, payment):
if class_type == 'first':
price = self.firstClassPrice
seats = self.firstClassSeats
else:
price = self.coachClassPrice
seats = self.coachClassSeats
if seats[row][seat]!='':
print("Seat is unavailable.")
return
if age <7 or age >=65:
price *=0.8 # Apply 20% discount
total_cost = price *(1+ self.taxRate)
if payment < total_cost:
print("Insufficient funds.")
return
seats[row][seat]= name
change = payment - total_cost
self.calculate_change(change)
print(f"Reservation successful for {name}. Change: ${change:.2f}")
def calculate_change(self, change):
denominations =[100,50,20,5,1,0.25,0.10,0.05,0.01]
change_distribution ={}
for denom in denominations:
count = int(change // denom)
change_distribution[denom]= count
change -= count * denom
print("Change distribution:", change_distribution)
def change_reservation(self, class_type, old_row, old_seat, new_row, new_seat, name):
if class_type == 'first':
seats = self.firstClassSeats
else:
seats = self.coachClassSeats
if seats[old_row][old_seat]!= name:
print("No reservation found for this seat.")
return
if seats[new_row][new_seat]!='':
print("New seat is already taken.")
return
seats[old_row][old_seat]=''
seats[new_row][new_seat]= name
print(f"Reservation changed for {name}.")
def print_seats(self):
print("First Class Seats:")
for i, row in enumerate(self.firstClassSeats):
print(f"Row {i+1}: ",["{:<12}".format(name[:12]) for name in row])
print("
Coach Class Seats:")
for i, row in enumerate(self.coachClassSeats):
print(f"Row {i+1}: ",["{:<12}".format(name[:12]) for name in row])
def run(self):
while True:
print("
Options:")
print("rf) Make a first class reservation")
print("rc) Make a coach class reservation")
print("cr) Change an existing reservation")
print("p) Print the listing of seats")
print("q) Quit")
choice = input("What would you like to do?: ")
if choice =='rf':
row = int(input("Enter row (1-2): "))
seat = int(input("Enter seat (1-4): "))
name = input("Enter name: ")
age = int(input("Enter age: "))
payment = float(input("Enter payment amount: "))
self.make_reservation('first', row, seat, name, age, payment)
elif choice =='rc':
row = int(input("Enter row (1-4): "))
seat = int(input("Enter seat (1-10): "))
name = input("Enter name: ")
age = int(input("Enter age: "))
payment = float(input("Enter payment amount: "))
self.make_reservation('coach', row, seat, name, age, payment)
elif choice =='cr':
class_type = input("Enter class type (first/coach): ")
old_row = int(input("Enter old row: "))
old_seat = int(input("Enter old seat: "))
new_row = int(input("Enter new row: "))
new_seat = int(input("Enter new seat: "))
name = input("Enter name: ")
self.change_reservation(class_type, old_row, old_seat, new_row, new_seat, name)
elif choice =='p':
self.print_seats()
elif choice =='q':
print("Exiting system.")
break
else:
print("Invalid option. Please try again.")
system = AirlineReservationSystem()
system.run()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!