设计自定义机动车类

class Vehicle:
    def __init__(self, vehicle_type, vehicle_no):
        self.vehicle_type = vehicle_type
        self.vehicle_no = vehicle_no

    def start(self):
        print(f"您乘坐的是{self.vehicle_type},{self.vehicle_no}已启动")

    def stop(self):
        print(f"您乘坐的是{self.vehicle_type},{self.vehicle_no}已停止")

class Taxi(Vehicle):
    def __init__(self, vehicle_type, vehicle_no, company):
        super().__init__(vehicle_type, vehicle_no)
        self.company = company

    def start(self):
        print(f"乘客您好!\n我是{self.company}的,我的车牌号:{self.vehicle_no}, 请问您要去哪里?")

    def stop(self):
        print(f"目的地到了,请您付款下车,感谢您乘坐{self.vehicle_type},欢迎下次乘坐~")

class Car(Vehicle):
    def __init__(self, vehicle_type, vehicle_no, owner):
        super().__init__(vehicle_type, vehicle_no)
        self.owner = owner

    def start(self):
        print(f"我是{self.owner},我的{self.vehicle_type}真好看!")

    def stop(self):
        print("目的地到啦,我们去玩儿吧!")

class Bus(Vehicle):
    def __init__(self, vehicle_type, vehicle_no, stations):
        super().__init__(vehicle_type, vehicle_no)
        self.stations = stations

    def start(self):
        print(f"我是{self.vehicle_type},上有天堂下游苏杭~")

    def stop(self):
        print(f"前方到站{self.stations}")

taxi = Taxi("杭州出租车", "浙A66666", "杭州xx集团")
car = Car("劳斯莱斯幻影", "浙A8888", "阿波波")
bus = Bus("杭州K155", "浙A15555", "立马回头")

taxi.start()
taxi.stop()

print("*"*50)

car.start()
car.stop()

print("*"*50)

bus.start()
bus.stop()
全部评论

相关推荐

01-23 14:54
同济大学 Java
热爱敲代码的程序媛:给你提几点【专业技能】这个模块里面可优化的地方:1.【具备JVM调优经验】可以去b站上搜一下JVM调优的视频,估计一两个小时凭你的学习能力就能掌握JVM调优的实践方面的技能。2.【MySql优化】MySql这一栏,你去b站或者找个博客看看MySql优化,学一下,如果你本身比较熟悉MySql语句的话,那基本半天时间凭你的学习能力MySql语句优化方面的技能你也能掌握个差不多。以上1,2两点主要是因为我看你专业技能大部分都说的是偏理论,没有写应用。再就是最后,你结合你的项目,想一想你的项目中哪些sql语句是可以用MySql优化的,到时候你面试的时候也好结合着说一下。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务