In: Computer Science
create a python program
You are assigned to implement the following baggage-check-in system at the airport.
The system keeps track of data for the following information: passenger, bags, and tickets.
The program must maintain passenger details like name, address, phone number, and the number of bags. Each passenger can have multiple bags and each bag has length, width, height, and weight. The passenger also has a ticket. The tickets are of two types, either a first-class ticket or an economy-ticket. The maximum weight allowed for a first-class ticket is 40 Kilos and the maximum weight allowed for an economy-ticket is 30 Kilos. The program must display all the details of the passenger, ticket, and number of bags and allowed weight. If the weight exceeds that of the respective ticket class, then the program will give appropriate message to indicate that the passenger cannot travel. Your program must throw an exception to indicate the failure.
Requirements
CONCEPT: WE USED HERE SIMPLE CLASS AND OBJECTS CONCEPTS WE TAKE HERE CLASS CONSTRUCTORS AND VARIOUS VALUES TO GET THE CHECK IN SYSTEM
''' class bags having the attributes as
given here below.. length width, and height
as given below... we fill all the heights
weights as below'''
class bags:
def __init__(self,l1,wd1,h1,w1):
self.length=l1
self.width=wd1
self.height=h1
self.weight=w1
'''we have the check_in_system class as given below
code .. we have all the attributes as
we take the constructors and the varioud
function.s we calculate_weight_of_all as extra
member function...'''
class check_in_system:
#constructors for assigning all the values to the attributes..
def __init__(self,n1,t1,ad1,nos,bags_no):
self.ticket_no=t1
self.name=n1
self.address=ad1
self.phone_no=nos
self.no_of_bags=bags_no
self.Pclass=""
self.total_weight1=0
def calculate_weight_of_all(self):
total=0.0
list=[]
'''enter the weight of all the bags alogn with length wi....
and then we take the each obj of bags type and then we
add all the weights'''
print("enter the length width,height & weight of each bags")
for i in range(self.no_of_bags):
l1=int(input())
wd1=int(input())
h1=int(input())
w1=int(input())
list.append( bags(l1,wd1,h1,w1) )
for obj in list:
total+=obj.weight
self.total_weight1=total
#we get the total and return
return total
#this is used to checkPassengerClass from the ticket_no..
def checkPassengerClass(self,ticket_no):
'''this is just anymously taken as if the ticket_no > 61345 then we think it as first_class.. and
else display_passenger_details'''
if ticket_no > 61345:
Pclass1="first_class"
else:
Pclass1="economy_class"
self.Pclass=Pclass1
return Pclass1
'''we check for checkOverWeight using this function here..
we have this as we count all the weights and then we
use the Pclass1 as economy_class and assing as given code..'''
def checkOverWeight(self,ticket_no):
Pclass1=self.checkPassengerClass(ticket_no)
total_weight=self.calculate_weight_of_all()
if(Pclass1=="first_class"):
if(total_weight>40):
return True
else:
return False
elif(Pclass1=="economy_class"):
if(total_weight>30):
return True
else:
return False
def display_passenger_details(self,ticket_no):
c1=self.checkPassengerClass(ticket_no)
if(self.checkOverWeight(ticket_no)==True):
print("cant traver checkOverWeight exception occured")
return
else:
print("name is ",self.name)
print("address is: ",self.address)
print("phone_no :",self.phone_no)
print("no_of_bags",self.no_of_bags)
print("total_weight is:",self.total_weight1)
print("class of the passenger is: ",self.Pclass)
print("")
def main():
#object 1 and 2 and 3 are below:
air1= check_in_system("newton",23435,"big city newyork",56545444,1)
air1.display_passenger_details(23435)
air2=check_in_system("sljf",4324,"ldkjfdklf",344545567,2)
air2.display_passenger_details(4324)
air3=check_in_system("sljf",432456,"ldkjfdklf",344545567,1)
air3.display_passenger_details(432456)
if __name__ =="__main__":
main()
Input:
4
6
4
23
4
6
4
23
5
8
9
12
6
12
89
15
Output:
enter the length width,height & weight of each bags
name is newton
address is: big city newyork
phone_no : 56545444
no_of_bags 1
total_weight is: 23.0
class of the passenger is: economy_class
enter the length width,height & weight of each bags
cant traver checkOverWeight exception occured
enter the length width,height & weight of each bags
name is sljf
address is: ldkjfdklf
phone_no : 344545567
no_of_bags 1
total_weight is: 15.0
class of the passenger is: first_class
Note: in case of nay query please ask in comment
Thank you
Upvote if helpful