-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q39.py
64 lines (47 loc) · 2.06 KB
/
Q39.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
57
58
59
60
61
62
63
64
class Ticket:
def __init__(self, ticket_id, event_name, price):
self.ticket_id = ticket_id
self.event_name = event_name
self.price = price
self.is_booked = False
def display_info(self):
print(f"Ticket ID: {self.ticket_id}, Event: {self.event_name}, Price: ${self.price:.2f}, Booked: {self.is_booked}")
def book_ticket(self):
if not self.is_booked:
self.is_booked = True
print("Ticket booked successfully!")
else:
print("Ticket is already booked.")
class MovieTicket(Ticket):
def __init__(self, ticket_id, movie_name, show_time, price):
super().__init__(ticket_id, f"Movie: {movie_name}, Show Time: {show_time}", price)
class ConcertTicket(Ticket):
def __init__(self, ticket_id, artist_name, venue, date, price):
super().__init__(ticket_id, f"Concert: {artist_name}, Venue: {venue}, Date: {date}", price)
class BookingSystem(Ticket):
def __init__(self):
super().__init__(ticket_id=None, event_name="Booking System", price=0)
self.available_tickets = []
def add_ticket(self, ticket):
self.available_tickets.append(ticket)
def display_available_tickets(self):
print("Available Tickets:")
for ticket in self.available_tickets:
ticket.display_info()
# Example usage:
if __name__ == "__main__":
# Create instances of subclasses
movie_ticket = MovieTicket(1, "Inception", "18:00", 15.99)
concert_ticket = ConcertTicket(2, "Coldplay", "Stadium XYZ", "2023-05-20", 49.99)
# Create an instance of BookingSystem
booking_system = BookingSystem()
# Add tickets to the booking system
booking_system.add_ticket(movie_ticket)
booking_system.add_ticket(concert_ticket)
# Display available tickets
booking_system.display_available_tickets()
# Book a ticket
movie_ticket.book_ticket()
concert_ticket.book_ticket()
# Display updated ticket information
booking_system.display_available_tickets()