Esempio n. 1
0
	def process_rental(self):
		answer = str.lower(raw_input('   Would you like to rent a car? Yes: "Y", No: "N" : '))
		if answer == 'y':
			answer = str.lower(raw_input('  Choose "p" for Petrol, "d" for Diesel, "e" for electric and "h" for Hybrid:   '))
			amount = int(raw_input('   How many would you like?  '))
			if answer == 'p':
				self.rent(self.petrol_cars, amount)
				choice = raw_input('   Write the model you would like: Toyota, Kia, Volkswagon, Ford:    ')
				petrol_car = PetrolCar()
				petrol_car.setMake(choice)
				mileage = int(raw_input('   Record the mileage here before you start driving. '))
				petrol_car.setMileage(mileage)
				print 'Your car is: ', petrol_car.getMake()
				print 'The current mileage is set at: ',  petrol_car.getMileage()
				return mileage
				
				
			elif answer == 'd':
				self.rent(self.diesel_cars, amount)
				choice = raw_input('   Write the model you would like: Nissan or Hyundai:  ')
				diesel_car = DieselCar()
				diesel_car.setMake(choice)
				mileage = int(raw_input('   Record the mileage here before you start driving. '))
				diesel_car.setMileage(mileage)
				print 'Your car is: ', diesel_car.getMake()
				print 'The current mileage is set at: ',  diesel_car.getMileage()
				return mileage
				
				
			elif answer == 'e':
				self.rent(self.electric_cars, amount)
				choice = raw_input('   We have a Nissan or a Tesla, please write your choice:   ')
				electric_car = ElectricCar()
				electric_car.setMake(choice)
				mileage = int(raw_input('   Record your mileage here before you start driving. '))
				electric_car.setMileage(mileage)
				print 'Your model is', electric_car.getMake()
				print 'Fuel cells available are', electric_car.getNumberFuelCells()
				print 'Your current mileage is set to:  ', electric_car.getMileage()
				return mileage
			else:
				self.rent(self.hybrid_cars, amount)			
				choice = raw_input(' what hybrid do you want, Prius or Lexus?  ')
				hybrid_car = HybridCar()
				hybrid_car.setMake(choice)
				mileage = int(raw_input('   Record your mileage here before you start driving.  '))
				hybrid_car.setMileage(mileage)
				print 'Your model is', hybrid_car.getMake()
				print 'Our hybrid cars come with :', hybrid_car.getNumberFuelCells(), 'fuel cells and ', hybrid_car.getNumberCylinders(), 'cylinders '
				print 'Your current mileage is set to:  ', hybrid_car.getMileage()
				return mileage
				
			car_fleet = CarFleet()
			car_fleet.rentCar(amount)
		if answer == 'n':
			self.process_returnCar()
		self.stock_count()
# A HybridCar Class is called by car3 allowing it to use the functions and variables of the class.  A hybrid is
# 1 part standard motor car and 1 part electric car so it will use a cylinder and a cell function.  The make
# takes in the value Toyota Prius and prints a message to the user.  The colour is set at blue and printed.
# Same functionality as other mileage in this case 100 is the value that is set, next 17 is added using move
# resulting in a value of 117kms.  The engineSize variable is set as 3.1.  Hybrid cars require both cells and
# cylinders so it will use both functions.
car3 = HybridCar()
car3.setMake('Toyota Prius')
print '\nOur hybrid option is ' + car3.getMake()

car3.setColour('Blue')
print('The colour is ' + car3.getColour())

car3.setMileage(100)
car3.move(17)
print('The mileage is ' + str(car3.getMileage())) + 'kms'
car3.engineSize = '3.1'
print 'The engine size is ' + car3.engineSize

car3.setNumberOfFuelCells(2)
print('The number of fuel cells is ' + str(car3.getNumberOfFuelCells()))
car3.setNumberOfFuelCylinders(1)
print('The number of fuel cylinders is ' + str(car3.getNumberOfFuelCylinders()))


# Car4 calls the PetrolCar class and performs similar functions as other class'.  The colour is red, mileage
# is set to 150 and increased by 25 to 175kms.  The engine size is set at 2.9.  The petrol car is a Toyota Corolla
# and has 3 cylinders set as the value for the variable NumberOfFuelCylinders.
car4 = PetrolCar()
car4.setMake('Toyota Corolla')
print '\nOur petrol option is ' + car4.getMake()
Esempio n. 3
0
print " Make of Electric car is    :" + carE.getMake()
print " Colour of the car is       :" + carE.getColour()
print " Number of fuel cells       :" + str(carE.getNumberFuelCells())
print " Milegae of Electric car is :" + str(carE.getMileage())
print "_________________________________________"

#Hybrid car details.
carH = HybridCar()
carH.setMake("Toyota Prius")
carH.setColour("Yellow")
carH.setNumberCylinders_Cells(4)
carH.setMileage(1500)
print " Make of Hybrid car is      :" + carH.getMake()
print " Colour of the car is       :" + carH.getColour()
print " Number of cylinders/ cells :" + str(carH.getNumberCylinders_Cells())
print " Milegae of Hybrid car is   :" + str(carH.getMileage())
print "_________________________________________"

print

#DBS rental has fleet of 40 cars: 20 petrol, 8 diesel, 4 electric and 8 hybrid.


#We initializied class Carrental object.
class Carrental(object):
    def __init__(self):
        self.petrol_cars = []
        self.diesel_cars = []
        self.electric_cars = []
        self.hybrid_cars = []
Esempio n. 4
0
print 'Number of cylinders: ' + str(car3.getNumberDieselCylinders())
print 'Mileage on the clock: ' + str(car3.getMileage())
print '------------------'

# Hybrid car
car4 = HybridCar()
car4.setMake('Ford')
car4.setModel('Fusion Hybrid')
car4.setColour('Blue')
car4.setMileage(600)
car4.setNumberVoltCells(28)
print 'Hybrid car type: ' + car4.getMake()
print 'Model: ' + car4.getModel()
print 'Colour: ' + car4.getColour()
print 'Number of volt cells: ' + str(car4.getNumberVoltCells())
print 'Mileage on the clock: ' + str(car4.getMileage())
print '------------------'


# DBS Rental Company with a fleet of 40 cars: 8 diesel, 8 hybrid, 4 electric and 20 petrol.
class DBS_Car_Rental(object):
    # initializing the class object
    def __init__(self):
        self.electric_cars = []
        self.petrol_cars = []
        self.diesel_cars = []
        self.hybrid_cars = []
        self.car_fleet = []
# setting up a function to define the current stock of the car fleet

    def current_stock(self):
    class TestHybridCar(unittest.TestCase):
        def setUp(self):
            # The HybridCar calls itself using self.
            self.hybrid_car = HybridCar()

        def test_HybridCar_fuel_cylinders(self):
            # Similar to petrol and diesel except default value is 1.  The default value is tested as well as 4, 6
            # and 3 which all result in true.
            self.assertEqual(1, self.hybrid_car.getNumberOfFuelCylinders())
            self.hybrid_car.setNumberOfFuelCylinders(4)
            self.assertEqual(4, self.hybrid_car.getNumberOfFuelCylinders())
            self.hybrid_car.setNumberOfFuelCylinders(6)
            self.assertEqual(6, self.hybrid_car.getNumberOfFuelCylinders())
            self.hybrid_car.setNumberOfFuelCylinders(3)
            self.assertEqual(3, self.hybrid_car.getNumberOfFuelCylinders())

        def test_HybridCar_fuel_cells(self):
            # Similar to ElectricCar test_car_fuel_cells.  The default value 1 is tested as well as 4 and 2.
            self.assertEqual(1, self.hybrid_car.getNumberOfFuelCells())
            self.hybrid_car.setNumberOfFuelCells(4)
            self.assertEqual(4, self.hybrid_car.getNumberOfFuelCells())
            self.hybrid_car.setNumberOfFuelCells(2)
            self.assertEqual(2, self.hybrid_car.getNumberOfFuelCells())

        def test_HybridCar_mileage_and_move(self):
            # As in other cases testing the mileage default value.  Then entering a value for move to ensure
            # it moves that amount to test the mileage of a car.  The car is moved by 7.7 to make 19.7 moved 0
            # output stays the same and lastly setMileage is tested with a value of 15 which is true.
            self.assertEqual(0, self.hybrid_car.getMileage())
            self.hybrid_car.move(12)
            self.assertEqual(12, self.hybrid_car.getMileage())
            self.hybrid_car.move(7.7)
            self.assertEqual(19.7, self.hybrid_car.getMileage())
            self.hybrid_car.move(0)
            self.assertEqual(19.7, self.hybrid_car.getMileage())
            self.hybrid_car.setMileage(15)
            self.assertEqual(15, self.hybrid_car.getMileage())

        def test_HybridCar_make(self):
            # Testing make function for HybridCar.
            self.assertEqual(' ', self.hybrid_car.getMake())
            self.hybrid_car.setMake('Chevrolet Malibu')
            self.assertEqual('Chevrolet Malibu', self.hybrid_car.getMake())
            self.hybrid_car.setMake('Chevrolet Cruz')
            self.assertEqual('Chevrolet Cruz', self.hybrid_car.getMake())

        def test_HybridCar_engineSize(self):
            # Testing engineSize for HybridCar.
            self.assertEqual(' ', self.hybrid_car.getEngineSize())
            self.hybrid_car.setEngineSize(1.6)
            self.assertEqual(1.6, self.hybrid_car.getEngineSize())
            self.hybrid_car.setEngineSize(1.8)
            self.assertEqual(1.8, self.hybrid_car.getEngineSize())

        def test_HybridCar_colour_and_paint(self):
            # Testing colour and paint for HybridCar.
            self.assertEqual(' ', self.hybrid_car.getColour())
            self.hybrid_car.paint('red')
            self.assertEqual('red', self.hybrid_car.getColour())
            self.hybrid_car.setColour('light blue')
            self.assertEqual('light blue', self.hybrid_car.getColour())