7-7 sdut-oop-7 答答租车系统(类的继承与多态 面向对象综合练习)- -python
写了很多冗余数据:车型名称可以不要
class Che:
id=0
name='A'
maxpeo=0
weight=0
meo=0
def __init__(self,id,name,maxpeo,weight,meo):
self.id=id
self.name=name
self.maxpeo=maxpeo
self.meo=meo
self.weight=weight
def getMaxpeo(self,n):
return self.maxpeo*n
def getWeight(self,n):
return self.weight*n
def getMeo(self,n):
return self.meo*n
class KeChe(Che):
def __init__(self,id,name,maxpeo,meo):
self.id=id
self.name=name
self.maxpeo=maxpeo
self.meo=meo
class HuoChe(Che):
def __init__(self,id,name,weight,meo):
self.id=id
self.name=name
self.weight=weight
self.meo=meo
ans=[]
ans.append(KeChe(1,"d",5,800))
ans.append(KeChe(2,"d",5,400))
ans.append(KeChe(3,"d",5,800))
ans.append(KeChe(4,"d",51,1300))
ans.append(KeChe(5,"d",55,1500))
ans.append(Che(6,"d",5,0.45,500))
ans.append(Che(7,"d",5,2.0,450))
ans.append(HuoChe(8,"d",3,200))
ans.append(HuoChe(9,"d",25,1500))
ans.append(HuoChe(10,"d",35,2000))
x=int(input())
if x==1:
n=int(input())
sum1=0.0
sum2=0.0
sum3=0.0
for i in range(n):
#a表示要租车的编号,
#b表示租用该车型的天数。
a,b=map(int,input().split())
sum1+=ans[a-1].getMaxpeo(b)
sum2+=ans[a-1].getWeight(b)
sum3+=ans[a-1].getMeo(b)
print(int(sum1),'%.2f' %sum2,int(sum3))
else:
print("0 0.00 0")