OOPS Assignment2
OOPS Assignment2
class Hotel:
def __init__(self,name):
self.name=name
self.rooms=[]
def add_room(self,room):
self.rooms.append(room)
def remove_room(self,room):
self.rooms.remove(room)
def display_room(self):
print("Room Number",room.no,"Status",room.check_status())
def availble_rooms(self):
if(room.status=="vacant"):
class Room:
def __init__(self,number,capacity):
self.no=number
self.capacity=capacity
self.status="vacant"
def check_status(self):
return self.status
def check_in(self):
if self.status=="vacant":
self.status="occupied"
else:
print("Room not vacant")
def check_out(self):
self.status="vacant"
taj=Hotel("Taj")
print(taj.name)
room1=Room(101,2)
room2=Room(102,2)
room3=Room(103,4)
room4=Room(104,1)
taj.add_room(room1)
taj.add_room(room2)
taj.add_room(room3)
taj.add_room(room4)
taj.rooms[1].check_in()
taj.rooms[1].check_out()
taj.rooms[2].check_in()
taj.availble_rooms()
Question 2
class Airport:
def __init__(self,name):
self.__name=name
self.__flights=[]
def __find_flight_by_flightnumber(self,number):
flag=1
if(flight.__number==number):
return flight
return None
def add_flight(self,flight):
self.__flights.append(flight)
def remove_flight(self,number):
flight=self.__find_flight_by_flightnumber(number)
if flight:
self.flights.remove(flight)
def upcoming_flights(self):
print("Upcoming flights")
if(flight._arrival_time>=datetime.now()):
flight.displaydetails()
def completed_flights(self):
print("Completed flights")
if(flight._dep_time<=datetime.now()):
flight.displaydetails()
def details_of_all_flights(self):
flight.displaydetails()
class Fligt:
def __init__(self,f_no,dest,dep_time,arrival_time):
self.__number=f_no
self.__dest=dest
self._dep_time=dep_time
self._arrival_time=arrival_time
def _isupcoming(self):
if(self.__arrival_time<datetime.now()):
return True
else:
return False
def update_dep(self,new_dep):
self._dep_time=new_dep
def update_arrival(self,new_arr):
self.__arrival_time=new_arr
def displaydetails(self):
print("Fligt
Number:",self.__number,"Destination:",self.__dest,"Arrival:",self._arrival_time,"Departure:o",self._dep
_time)
Delhi=Airport("Delhi")
f1=Fligt("6E1","Pune",datetime(2023,11,15,12),datetime(2023,11,23,14))
f2=Fligt("6E2","Mumbai",datetime(2023,11,12,12),datetime(2023,11,12,14))
Delhi.add_flight(f1)
Delhi.add_flight(f2)
Delhi.details_of_all_flights()
f2.update_dep(datetime(2023,12,15))
Delhi.completed_flights()
Delhi.upcoming_flights()
Question 3
import math
class Shape():
def area(self):
pass
class Circle(Shape):
PI=math.pi
self.radius = radius
def area(self):
class Rectangle(Shape):
self.length = length
self.width = width
def area(self):
class Triangle(Shape):
self.base = base
self.height = height
def area(self):
class ShapeAreaCalculator:
@staticmethod
def calculate_area(shape):
return shape.area()
while True:
print("Choose shape:")
if choice == 1:
circle = Circle(radius)
elif choice == 2:
elif choice == 4:
break
else: