Advertisement
Guest User

Python - cars as objects

a guest
Jan 27th, 2014
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.57 KB | None | 0 0
  1. class Vehicle(object):  # no instance of this class should be created
  2.  
  3.     def __init__(self, typ, make, model, color, year, miles):
  4.         self.typ = typ
  5.         self.make = make
  6.         self.model = model
  7.         self.color = color.lower()
  8.         self.year = year
  9.         self.miles = miles
  10.  
  11.     def vehicle_print(self):
  12.             print('Vehicle Type: ' + str(self.typ))
  13.             print('Make: ' + str(self.make))
  14.             print('Model: ' + str(self.model))
  15.             print('Color: ' + str(self.color))
  16.             print('Year: ' + str(self.year))
  17.             print('Miles driven: ' + str(self.miles))
  18.  
  19.  
  20. class GasVehicle(Vehicle):
  21.  
  22.     def __init__(self, fuel_tank, *args):
  23.         self.fuel_tank = fuel_tank
  24.         Vehicle.__init__(self, *args)
  25.  
  26.     def vehicle_print(self):
  27.         Vehicle.vehicle_print(self)
  28.         print('Fuel capacity (gallons): ' + str(self.fuel_tank))
  29.  
  30.  
  31. class ElectricVehicle(Vehicle):
  32.  
  33.     def __init__(self, energy_storage, *args):
  34.         self.energy_storage = energy_storage
  35.         Vehicle.__init__(self, *args)
  36.  
  37.     def vehicle_print(self):
  38.         Vehicle.vehicle_print(self)
  39.         print('Energy Storage (Kwh): ' + str(self.energy_storage))
  40.  
  41.  
  42. class HeavyVehicle(GasVehicle):  # no instance of this class should be created
  43.  
  44.     def __init__(self, max_weight, wheels, length, *args):
  45.         self.max_weight = max_weight
  46.         self.wheels = wheels
  47.         self.length = length
  48.         GasVehicle.__init__(self, *args)
  49.  
  50.     def vehicle_print(self):
  51.         GasVehicle.vehicle_print(self)
  52.         print('Maximum load (tons): ' + str(self.max_weight))
  53.         print('Wheels: ' + str(self.wheels))
  54.         print('Length (m): ' + str(self.length))
  55.  
  56.  
  57. class ConstructionTruck(HeavyVehicle):
  58.  
  59.     def __init__(self, cargo, *args):
  60.         self.cargo = cargo
  61.         HeavyVehicle.__init__(self, *args)
  62.  
  63.     def vehicle_print(self):
  64.         HeavyVehicle.vehicle_print(self)
  65.         print('Cargo: ' + str(self.cargo))
  66.  
  67.  
  68. class Bus(HeavyVehicle):
  69.  
  70.     def __init__(self, seats, * args):
  71.         self.seats = seats
  72.         HeavyVehicle.__init__(self, *args)
  73.  
  74.     def vehicle_print(self):
  75.         HeavyVehicle.vehicle_print(self)
  76.         print('Number of seats: ' + str(self.seats))
  77.  
  78.  
  79. class HighPerformance(GasVehicle):  # no instance of this class should be created
  80.  
  81.     def __init__(self, hp, top_speed, *args):
  82.         self.hp = hp
  83.         self.top_speed = top_speed
  84.         GasVehicle.__init__(self, *args)
  85.  
  86.     def vehicle_print(self):
  87.         GasVehicle.vehicle_print(self)
  88.         print('Horse power: ' + str(self.hp))
  89.         print('Top speed: ' + str(self.top_speed))
  90.  
  91.  
  92. class SportCar(HighPerformance):
  93.  
  94.     def __init__(self, gear_box, drive_system, *args):
  95.         self.gearbox = gear_box
  96.         self.drive_system = drive_system
  97.         HighPerformance.__init__(self, *args)
  98.  
  99.     def vehicle_print(self):
  100.         HighPerformance.vehicle_print(self)
  101.         print('Gear box: ' + self.gearbox)
  102.         print('Drive system: ' + self.drive_system)
  103.  
  104.  
  105.  
  106.  
  107. bmw = GasVehicle(30, 'SUV', 'BMW', 'X5', 'silver', 2003, 120300)  # regular car
  108. bmw.vehicle_print()
  109. print
  110. tesla = ElectricVehicle(85, 'Sport', 'Tesla', 'Model S', 'red', 2014, 1243)  # electric car
  111. tesla.vehicle_print()
  112. print
  113. lambo = SportCar('manual', 'rear wheel', 650, 160, 23, 'race car', 'Lamborgini', 'Enzo', 'dark silver', 2014, 3500)  # sportscar
  114. lambo.vehicle_print()
  115. print
  116. truck = ConstructionTruck('cement', 4, 12, 21, 190, 'transport', 'Dirt Inc.', 'Dirt Blaster 100', 'blue', 1992, 120030)  # Construction truck
  117. truck.vehicle_print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement