class TestPetrolCar(TestEngineCar): def setUp(self): TestEngineCar.setUp(self) self.petrolCar = PetrolCar() def test_petrol_default_constructor(self): self.assertEquals('', self.petrolCar.petrolType) def test_petrol_get_method(self): self.assertEquals('', self.petrolCar.getPetrolType()) def test_petrol_set_method(self): self.petrolCar.setPetrolType('Unleaded') self.assertEquals('Unleaded', self.petrolCar.getPetrolType())
def create_current_stock(self): for i in range(24): self.petrol_cars.append(PetrolCar()) for i in range(8): self.diesel_cars.append(DieselCar()) for i in range(4): self.electric_cars.append(ElectricCar()) for i in range(4): self.hybrids.append(HybridCar())
def test_petrol_car_number_cylinders(self): petrol_car = PetrolCar() self.assertEqual(1, petrol_car.getNumberCylinders()) petrol_car.setNumberCylinders(6) self.assertEqual(6, petrol_car.getNumberCylinders()) petrol_car.setNumberCylinders(4) self.assertEqual(4, petrol_car.getNumberCylinders()) def test_diesel_car_number_diesel_cylinders(self): diesel_car = DieselCar() self.assertEqual(1, diesel_car.getNumberDieselCylinders()) diesel_car.setNumberDieselCylinders(4) self.assertEqual(4, diesel_car.getNumberDieselCylinders()) def test_hybrid_car_number_volt_cells(self): hybrid_car = HybridCar() self.assertEqual(1, hybrid_car.getNumberVoltCells()) hybrid_car.setNumberVoltCells(28) self.assertEqual(28, hybrid_car.getNumberVoltCells())
def __init__(self): self.__petrol_cars = [] self.__diesel_cars = [] self.__electric_cars = [] self.__hybrid_cars = [] self.__csv_header = '' for i in range(1, 21): self.__petrol_cars.append(PetrolCar()) for i in range(1, 11): self.__diesel_cars.append(DieselCar()) for i in range(1, 7): self.__electric_cars.append(ElectricCar()) for i in range(1, 5): self.__hybrid_cars.append(HybridCar())
def create_current_stock(self, typecar, start): #set up the initial stock for each type of cars # it has been called in the main (row 100) if typecar == 'E': for i in range(start): self.electric_cars.append(ElectricCar()) elif typecar == 'P': for i in range(start): self.petrol_cars.append(PetrolCar()) elif typecar == 'D': for i in range(start): self.diesel_cars.append(DieselCar()) elif typecar == 'H': for i in range(start): self.hybrid_cars.append(HybridCar())
def create_current_stock(self): self.overallTotal = 40 # total stock the dealer plans on having initially uniqueID = 100 # each car will have it's own unique ID, this is the starting integer # Making an assumption here that the dealer will maintain the current # ratio of 50% petrol, 20% diesel, 10% electric and 20% hybrid # this could be changed to fixed qtys of each # 'build' the fleet! for i in range(int(self.overallTotal * 0.5)): self.petrol_cars.append(PetrolCar(uniqueID)) uniqueID += 1 for i in range(int(self.overallTotal * 0.2)): self.diesel_cars.append(DieselCar(uniqueID)) uniqueID += 1 for i in range(int(self.overallTotal * 0.2)): self.hybrid_cars.append(HybridCar(uniqueID)) uniqueID += 1 for i in range(int(self.overallTotal * 0.1)): self.electric_cars.append(ElectricCar(uniqueID)) uniqueID += 1
def test_car_rental_set_methods(self): self.carRental.setFleet(40) self.assertEquals(40, self.carRental.getFleet()) petrolCar = PetrolCar() dieselCar = DieselCar() electricCar = ElectricCar() hybridCar = HybridCar() self.carRental.setAvailablePetrolCars([petrolCar, petrolCar]) self.assertEquals([petrolCar, petrolCar], self.carRental.getAvailablePetrolCars()) self.carRental.setAvailableDieselCars( [dieselCar, dieselCar, dieselCar]) self.assertEquals([dieselCar, dieselCar, dieselCar], self.carRental.getAvailableDieselCars()) self.carRental.setAvailableElectricCars([electricCar, electricCar]) self.assertEquals([electricCar, electricCar], self.carRental.getAvailableElectricCars()) self.carRental.setAvailableHybridCars([hybridCar, hybridCar]) self.assertEquals([hybridCar, hybridCar], self.carRental.getAvailableHybridCars())
def returnCar(self, carType): # checks car type if carType == 'Petrol': # call checkRentals function to determine whether or not the car type is on rentals index = self.checkRentals('Petrol') # if car type is in rentals then remove it from rentals and add it to the associated array if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(PetrolCar()) return 'You have returned the car' # else car type is not in rentals else: return 'No petrol cars currently on rental' elif carType == 'Diesel': index = self.checkRentals('Diesel') if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(DieselCar()) return 'You have returned the car' else: return 'No diesel cars currently on rental' elif carType == 'Electric': index = self.checkRentals('Electric') if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(ElectricCar()) return 'You have returned the car' else: return 'No electric cars currently on rental' elif carType == 'Hybrid': index = self.checkRentals('Hybrid') if index != -1: self.rental_cars.pop(index) self.petrol_cars.append(HybridCar()) return 'You have returned the car' else: return 'No hybrids currently on rental'
def setUp(self): TestCar.setUp(self) self.petrolCar = PetrolCar()
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( ) 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( ) 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( ) 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( ) car_fleet = CarFleet() car_fleet.rentCar(amount) if answer == 'n': self.process_returnCar() self.stock_count()
def setUp(self): TestEngineCar.setUp(self) self.petrolCar = PetrolCar()
class CarRentalApp(object): ## create car objects global car, engineCar, petrolCar, dieselCar, electricCar, hybridCar, carRental car = Car() engineCar = EngineCar() petrolCar = PetrolCar() dieselCar = DieselCar() electricCar = ElectricCar() hybridCar = HybridCar() carRental = CarRental() ## create customer object global customer customer = Customer() def fleetInfo(): ## construct car fleet carRental.setFleet(40) fleet = carRental.getFleet() availablePetrol = int(0.60 * fleet) availableDiesel = int(0.20 * fleet) availableElectric = int(0.10 * fleet) availableHybrid = int(0.10 * fleet) carRental.setAvailablePetrolCars([]) carRental.setAvailableDieselCars([]) carRental.setAvailableElectricCars([]) carRental.setAvailableHybridCars([]) for p in range(1, availablePetrol + 1): carRental.availablePetrolCars.append(petrolCar) for d in range(1, availableDiesel + 1): carRental.availableDieselCars.append(dieselCar) for e in range(1, availableElectric + 1): carRental.availableElectricCars.append(electricCar) for h in range(1, availableHybrid + 1): carRental.availableHybridCars.append(hybridCar) def customerDetails(): ## print quit message print('Type "q" to quit this program') ## obtain input form user while True: name = input('Please enter Customer name: ') if name == 'q' or name == 'Q': quit() ## check user did not just press return button ## and all characters are alphabetic ## note: unfortunately the isalpha method will not work in cases ## whereby some african names contain an exclamation mark if name.isalpha() == False: print('Sorry, name not recognised. Please try again.') continue customer.setName(name) licence = input('Please enter Customer driving licence number: ') if licence == 'q' or customer.licence == 'Q': quit() if licence == '': print('Sorry, licence not valid. Please try again.') continue customer.setLicence(licence) print('Type "H" if Customer wishes to hire a car from the fleet.') print('Type "R" if Customer is returning a car to the fleet.') global hireReturn hireReturn = input('Hire or Return?: ') if hireReturn == 'q': quit() hireReturn = hireReturn.lower() if (hireReturn != 'h') and (hireReturn != 'r'): print('Invalid input. Please try again.') continue break return hireReturn def carInfo(): ## obtain car choice while True: print('What type of car is being hired/returned?:') print('Type "P" for petrol') print('Type "D" for diesel') print('Type "E" for electric') print('Type "H" for hybrid') global carChoice carChoice = input('Enter car type now: ') carChoice = carChoice.lower() if carChoice == 'q': quit() carChoiceOptions = ['p', 'd', 'e', 'h'] ## check for valid carChoice if carChoice not in carChoiceOptions: print('Invalid car choice. Please try agsin.') continue ## check if car choice available if hireReturn == 'h': if ( (carChoice == 'p') and (len(carRental.getAvailablePetrolCars()) <= 0) ) \ or ( (carChoice == 'd') and (len(carRental.getAvailableDieselCars()) <= 0) ) \ or ( (carChoice == 'e') and (len(carRental.getAvailableElectricCars()) <= 0) ) \ or ( (carChoice == 'h') and (len(carRental.getAvailableHybridCars()) <= 0) ): print( 'Apologies, there are none of this car type currently in the fleet.' ) print('Please choose alternative car type.') continue break return carChoice def transmissionInfo(): ##obtain transmission info while True: if hireReturn == 'h': print( 'Does Customer prefer an Automatic or a Manual transmission?:' ) print('Type "A" for Automatic') print('Type "M" for Manual') transmissionChoice = input('Enter transmission preference: ') transmissionChoice = transmissionChoice.lower() if transmissionChoice == 'q': quit() transmissionChoiceOptions = ['a', 'm'] ## check for valid transmissionChoice if transmissionChoice not in transmissionChoiceOptions: print('Invalid transmission choice. Please try agsin.') continue if transmissionChoice == 'a': engineCar.setTransmission('Automatic') if transmissionChoice == 'm': engineCar.setTransmission('Manual') break def carMakeInfo(): ##obtain car make info while True: if hireReturn == 'h': print('Does Customer prefer a Ford or a Toyota?:') print('Type "F" for Ford') print('Type "T" for Toyota') makeChoice = input('Enter Make preference: ') makeChoice = makeChoice.lower() if makeChoice == 'q': quit() makeChoiceOptions = ['f', 't'] ## check for valid makeChoice if makeChoice not in makeChoiceOptions: print('Invalid Make choice. Please try agsin.') continue if makeChoice == 'f': car.setMake('Ford') if makeChoice == 't': car.setMake('Toyota') break def carModelInfo(): ##obtain car model info while True: if car.getMake() == 'Ford': print('Does Customer prefer a Focus or a Mondeo?:') print('Type "F" for Focus') print('Type "M" for Mondeo') modelChoice = input('Enter Model preference: ') modelChoice = modelChoice.lower() if modelChoice == 'q': quit() modelChoiceOptions = ['f', 'm'] ## check for valid modelChoice if modelChoice not in modelChoiceOptions: print('Invalid Model choice. Please try agsin.') continue if modelChoice == 'f': car.setModel('Focus') if modelChoice == 'm': car.setModel('Mondeo') break while True: if car.getMake() == 'Toyota': print('Does Customer prefer a Corolla or an Avensis?:') print('Type "C" for Corolla') print('Type "A" for Avensis') modelChoice = input('Enter Model preference: ') modelChoice = modelChoice.lower() if modelChoice == 'q': quit() modelChoiceOptions = ['c', 'a'] ## check for valid modelChoice if modelChoice not in modelChoiceOptions: print('Invalid make choice. Please try agsin.') continue if modelChoice == 'c': car.setModel('Corolla') if modelChoice == 'a': car.setModel('Avensis') break def petrolCarInfo(): ##obtain fuel info while True: if carChoice == 'p': print('Does Customer have a fuel preference?:') print('Type "L" for leaded') print('Type "U" for unleaded') fuelChoice = input('Enter Customer choice now: ') fuelChoice = fuelChoice.lower() if fuelChoice == 'q': quit() fuelChoiceOptions = ['l', 'u'] ## check for valid fuelChoice if fuelChoice not in fuelChoiceOptions: print('Invalid fuel choice. Please try agsin.') continue if fuelChoice == 'l': petrolCar.setPetrolType('Leaded') if fuelChoice == 'u': petrolCar.setPetrolType('Unleaded') break def dieselCarInfo(): ##obtain turbo info while True: if carChoice == 'd': print('Does Customer prefer standard or turbo?:') print('Type "S" for standard') print('Type "T" for turbo') turboChoice = input('Enter Customer choice now: ') turboChoice = turboChoice.lower() if turboChoice == 'q': quit() turboChoiceOptions = ['s', 't'] ## check for valid turboChoice if turboChoice not in turboChoiceOptions: print('Invalid turbo choice. Please try agsin.') continue if turboChoice == 's': dieselCar.setDieselTurbo(False) if turboChoice == 't': dieselCar.setDieselTurbo(True) break def electricCarInfo(): ##obtain fuelCells info while True: if carChoice == 'e': print('Does Customer prefer battery or capacitor?:') print('Type "B" for battery') print('Type "C" for capacitor') fuelCellsChoice = input('Enter Customer choice now: ') fuelCellsChoice = fuelCellsChoice.lower() if fuelCellsChoice == 'q': quit() fuelCellsChoiceOptions = ['b', 'c'] ## check for valid fuelCellsChoice if fuelCellsChoice not in fuelCellsChoiceOptions: print('Invalid fuel cell choice. Please try agsin.') continue if fuelCellsChoice == 'b': electricCar.setFuelCells('Battery') if fuelCellsChoice == 'c': electricCar.setFuelCells('Capacitor') break def hybridCarInfo(): ##obtain brake info while True: if carChoice == 'h': print( 'Does Customer prefer standard or regenerative braking system?:' ) print('Type "S" for standard brake system') print('Type "R" for regenerative brake system') brakeChoice = input('Enter Customer choice now: ') brakeChoice = brakeChoice.lower() if brakeChoice == 'q': quit() brakeChoiceOptions = ['s', 'r'] ## check for valid brakeChoice if brakeChoice not in brakeChoiceOptions: print('Invalid brake choice. Please try agsin.') continue if brakeChoice == 's': hybridCar.setHybridBrake(False) if brakeChoice == 'r': hybridCar.setHybridBrake(True) break def updateFleet(carChoice, hireReturn): ## remove/add one (1) car to/from fleet fleet = carRental.getFleet() if carChoice == 'p': if (hireReturn == 'h'): carRental.availablePetrolCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availablePetrolCars.append(petrolCar) fleet += 1 else: print('Hell has just frozen over. Petrol debug necessary!') quit() elif carChoice == 'd': if (hireReturn == 'h'): carRental.availableDieselCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableDieselCars.append(dieselCar) fleet += 1 else: print('Hell has just frozen over. Diesel debug necessary!') quit() elif carChoice == 'e': if (hireReturn == 'h'): carRental.availableElectricCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableElectricCars.append(electricCar) fleet += 1 else: print('Hell has just frozen over. Electric debug necessary!') quit() elif carChoice == 'h': if (hireReturn == 'h'): carRental.availableHybridCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableHybridCars.append(hybridCar) fleet += 1 else: print('Hell has just frozen over. Hybrid debug necessary!') quit() else: print('Woah ... back up the apple-cart. Debug required now!') quit() def calculateHirePeriod(hireReturn): while True: print('How many days does Customer require?') print('Number must be between 1 and 28 (inclusive).') hirePeriod = input('Please enter number of days: ') if hirePeriod == 'q': quit() try: hirePeriod = int(hirePeriod) if (1 <= hirePeriod) and (hirePeriod <= 28): break else: print('Hire period must be between 1 and 28.') except: print("Invalid input. Try again.") return hirePeriod def calculateHireCharge(hireReturn, hirePeriod): ## hire rates for large cars (i.e. Avensis & Mondeo): ## are 50 euro per day for the first 10 days ## and 35 euro per day thereafter ## hire rates for small cars (i.e. Corolla & Focus): ## are 40 euro per day for the first 10 days ## and 25 euro per day thereafter if hirePeriod <= 10: if (car.getModel() == 'Avensis') or (car.getModel() == 'Mondeo'): hireCharge = hirePeriod * 50.00 if (car.getModel() == 'Corolla') or (car.getModel() == 'Focus'): hireCharge = hirePeriod * 40.00 elif (10 < hirePeriod) and (hirePeriod <= 28): if (car.getModel() == 'Avensis') or (car.getModel() == 'Mondeo'): hireCharge = 500 + ((hirePeriod - 10) * 35.00) if (car.getModel() == 'Corolla') or (car.getModel() == 'Focus'): hireCharge = 400 + ((hirePeriod - 10) * 25.00) else: print("Oops! ... we shouldn't be here!") quit() return hireCharge fleetInfo() hireReturn = customerDetails() carInfo() transmissionInfo() carMakeInfo() carModelInfo() petrolCarInfo() dieselCarInfo() electricCarInfo() hybridCarInfo() availableCars = updateFleet(carChoice, hireReturn) if hireReturn == 'h': customer.hirePeriod = calculateHirePeriod(hireReturn) customer.hireCharge = calculateHireCharge(hireReturn, customer.hirePeriod) print('Customer name:\t\t\t', customer.getName()) print('Customer licence:\t\t', customer.getLicence()) if hireReturn == 'r': print('Thanks for returning the car.') print('Hope to see you again soom.') if hireReturn == 'h': print('Make of car hired:\t\t', car.getMake()) print('Model of car hired:\t\t', car.getModel()) print('Transmission of car hired:\t', engineCar.getTransmission()) if carChoice == 'p': print('Petrol type:\t\t\t', petrolCar.getPetrolType()) if carChoice == 'd': print('Has turbo?:\t\t\t', dieselCar.getDieselTurbo()) if carChoice == 'e': print('Fuel cell type:\t\t\t', electricCar.getFuelCells()) if carChoice == 'h': print('Regenerative braking system:\t', hybridCar.getHybridBrake()) print('Hire period (days):\t\t', customer.hirePeriod) print('Hire charge (euro):\t\t', customer.hireCharge)
def setUp(self): # The PetrolCar class calls itself. self.petrol_car = PetrolCar()
def setUp(self): self.car = PetrolCar()
# Electric car car1 = ElectricCar() car1.setMake('Tesla') car1.setModel('Model S') car1.setColour('Pearl') car1.setMileage(523) car1.setNumberFuelCells(2) print 'Electric car type: ' + car1.getMake() print 'Model: ' + car1.getModel() print 'Colour: ' + car1.getColour() print 'Number of fuel cells: ' + str(car1.getNumberFuelCells()) print 'Mileage on the clock: ' + str(car1.getMileage()) print '------------------' #Petrol car car2 = PetrolCar() car2.setMake('Toyota') car2.setModel('Yaris') car2.setColour('Green') car2.setMileage(653) car2.setNumberCylinders(4) print 'Petrol car type: ' + car2.getMake() print 'Model: ' + car2.getModel() print 'Colour: ' + car2.getColour() print 'Number of cylinders: ' + str(car2.getNumberCylinders()) print 'Mileage on the clock: ' + str(car2.getMileage()) print '------------------' # Diesel car car3 = DieselCar() car3.setMake('Ford')
def __load_petrol_car(self, cols): # Create petrol car from CSV line and add to petrol car list. car = PetrolCar(cols[1], cols[2], cols[3], cols[4], float(cols[6])) self.__load_car_rental_status(car, cols[5]) self.get_petrol_cars().append(car)
class CarRentalApp(object): ## create car objects global car, petrolCar, dieselCar, electricCar, hybridCar, carRental car = Car() # engineCar = EngineCar() petrolCar = PetrolCar() dieselCar = DieselCar() electricCar = ElectricCar() hybridCar = HybridCar() carRental = CarRental() ## create customer object global customer customer = Customer() def fleetInfo(): ## construct car fleet carRental.setFleet(40) fleet = carRental.getFleet() availablePetrol = int(0.50 * fleet) availableDiesel = int(0.20 * fleet) availableElectric = int(0.10 * fleet) availableHybrid = int(0.20 * fleet) carRental.setAvailablePetrolCars([]) carRental.setAvailableDieselCars([]) carRental.setAvailableElectricCars([]) carRental.setAvailableHybridCars([]) for p in range(1, availablePetrol + 1): carRental.availablePetrolCars.append(petrolCar) for d in range(1, availableDiesel + 1): carRental.availableDieselCars.append(dieselCar) for e in range(1, availableElectric + 1): carRental.availableElectricCars.append(electricCar) for h in range(1, availableHybrid + 1): carRental.availableHybridCars.append(hybridCar) def customerDetails(): ## print quit message print 'Type "q" to quit this program' ## obtain input form user while True: name = raw_input('Enter Customer name please: ') if name == 'q' or name == 'Q': quit() if name.isalpha() == False: print 'Sorry, Please try again.' continue customer.setName(name) print 'Type "H" for hire a car from the fleet.' print 'Type "R" for a car to the fleet.' global hireReturn hireReturn = raw_input('Hire or Return?: ') if hireReturn == 'q': quit() hireReturn = hireReturn.lower() if (hireReturn != 'h') and (hireReturn != 'r'): print 'Invalid input. Please try again.' continue break return hireReturn def carInfo(): ## obtain car choice while True: print 'What type of car is being hired or returned?:' print 'Type "P" for petrol' print 'Type "D" for diesel' print 'Type "E" for electric' print 'Type "H" for hybrid' global carChoice carChoice = raw_input('Enter car type now: ') carChoice = carChoice.lower() if carChoice == 'q': quit() carChoiceOptions = ['p', 'd', 'e', 'h'] ## check for valid carChoice if carChoice not in carChoiceOptions: print 'Invalid car choice. Please try agsin.' continue ## check if car choice available if hireReturn == 'h': if ( (carChoice == 'p') and (len(carRental.getAvailablePetrolCars()) <= 0) ) \ or ( (carChoice == 'd') and (len(carRental.getAvailableDieselCars()) <= 0) ) \ or ( (carChoice == 'e') and (len(carRental.getAvailableElectricCars()) <= 0) ) \ or ( (carChoice == 'h') and (len(carRental.getAvailableHybridCars()) <= 0) ): print 'Sorry, there are none of this car type currently in the fleet.' print 'Please choose alternative car type.' continue break return carChoice def carMakeInfo(): ##obtain car make info while True: if hireReturn == 'h': print 'Does Customer prefer a Ford or a Toyota?:' print 'Type "F" for Ford' print 'Type "T" for Toyota' makeChoice = raw_input('Enter Make preference: ') makeChoice = makeChoice.lower() if makeChoice == 'q': quit() makeChoiceOptions = ['f', 't'] ## check for valid makeChoice if makeChoice not in makeChoiceOptions: print 'Invalid Make choice. Please try again.' continue if makeChoice == 'f': car.setMake('Ford') if makeChoice == 't': car.setMake('Toyota') break def carModelInfo(): ##obtain car model info while True: if car.getMake() == 'Ford': print 'Does Customer prefer a Focus or a Mondeo?:' print 'Type "F" for Focus' print 'Type "M" for Mondeo' modelChoice = raw_input('Enter Model preference: ') modelChoice = modelChoice.lower() if modelChoice == 'q': quit() modelChoiceOptions = ['f', 'm'] ## check for valid modelChoice if modelChoice not in modelChoiceOptions: print 'Invalid Model choice. Please try agsin.' continue if modelChoice == 'f': car.setModel('Focus') if modelChoice == 'm': car.setModel('Mondeo') break while True: if car.getMake() == 'Toyota': print 'Does Customer prefer a Corolla or an Avensis?:' print 'Type "C" for Corolla' print 'Type "A" for Avensis' modelChoice = raw_input('Enter Model preference: ') modelChoice = modelChoice.lower() if modelChoice == 'q': quit() modelChoiceOptions = ['c', 'a'] ## check for valid modelChoice if modelChoice not in modelChoiceOptions: print 'Invalid make choice. Please try agsin.' continue if modelChoice == 'c': car.setModel('Corolla') if modelChoice == 'a': car.setModel('Avensis') break def petrolCarInfo(): ##obtain fuel info while True: if carChoice == 'p': print 'Does Customer have a fuel preference?:' print 'Type "L" for leaded' print 'Type "U" for unleaded' fuelChoice = raw_input('Enter Customer choice now: ') fuelChoice = fuelChoice.lower() if fuelChoice == 'q': quit() fuelChoiceOptions = ['l', 'u'] ## check for valid fuelChoice if fuelChoice not in fuelChoiceOptions: print 'Invalid fuel choice. Please try agsin.' continue if fuelChoice == 'l': petrolCar.setPetrolType('Leaded') if fuelChoice == 'u': petrolCar.setPetrolType('Unleaded') break def dieselCarInfo(): ##obtain turbo info while True: if carChoice == 'd': print 'Does Customer prefer standard or turbo?:' print 'Type "S" for standard' print 'Type "T" for turbo' turboChoice = raw_input('Enter Customer choice now: ') turboChoice = turboChoice.lower() if turboChoice == 'q': quit() turboChoiceOptions = ['s', 't'] ## check for valid turboChoice if turboChoice not in turboChoiceOptions: print 'Invalid turbo choice. Please try agsin.' continue if turboChoice == 's': dieselCar.setDieselTurbo(False) if turboChoice == 't': dieselCar.setDieselTurbo(True) break def electricCarInfo(): ##obtain fuelCells info while True: if carChoice == 'e': print 'Does Customer prefer battery or capacitor?:' print 'Type "B" for battery' print 'Type "C" for capacitor' fuelCellsChoice = raw_input('Enter Customer choice now: ') fuelCellsChoice = fuelCellsChoice.lower() if fuelCellsChoice == 'q': quit() fuelCellsChoiceOptions = ['b', 'c'] ## check for valid fuelCellsChoice if fuelCellsChoice not in fuelCellsChoiceOptions: print 'Invalid fuel cell choice. Please try agsin.' continue if fuelCellsChoice == 'b': electricCar.setFuelCells('Battery') if fuelCellsChoice == 'c': electricCar.setFuelCells('Capacitor') break def hybridCarInfo(): ##obtain brake info while True: if carChoice == 'h': print 'Does Customer prefer standard or regenerative braking system?:' print 'Type "S" for standard brake system' print 'Type "R" for regenerative brake system' brakeChoice = raw_input('Enter Customer choice now: ') brakeChoice = brakeChoice.lower() if brakeChoice == 'q': quit() brakeChoiceOptions = ['s', 'r'] ## check for valid brakeChoice if brakeChoice not in brakeChoiceOptions: print 'Invalid brake choice. Please try agsin.' continue if brakeChoice == 's': hybridCar.setHybridBrake(False) if brakeChoice == 'r': hybridCar.setHybridBrake(True) break def updateFleet(carChoice, hireReturn): ## remove/add one (1) car to/from fleet fleet = carRental.getFleet() if carChoice == 'p': if (hireReturn == 'h'): carRental.availablePetrolCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availablePetrolCars.append(petrolCar) fleet += 1 else: print 'Hell has just frozen over. Petrol debug necessary!' quit() elif carChoice == 'd': if (hireReturn == 'h'): carRental.availableDieselCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableDieselCars.append(dieselCar) fleet += 1 else: print 'Hell has just frozen over. Diesel debug necessary!' quit() elif carChoice == 'e': if (hireReturn == 'h'): carRental.availableElectricCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableElectricCars.append(electricCar) fleet += 1 else: print 'Hell has just frozen over. Electric debug necessary!' quit() elif carChoice == 'h': if (hireReturn == 'h'): carRental.availableHybridCars.pop() fleet -= 1 elif (hireReturn == 'r'): carRental.availableHybridCars.append(hybridCar) fleet += 1 else: print 'Hell has just frozen over. Hybrid debug necessary!' quit() else: print 'Woah ... back up the apple-cart. Debug required now!' quit() def calculateHirePeriod(hireReturn): while True: print 'How many days does Customer require?' print 'Number must be between 1 and 28 (inclusive).' hirePeriod = raw_input('Please enter number of days: ') if hirePeriod == 'q': quit() try: hirePeriod = int(hirePeriod) if (1 <= hirePeriod) and (hirePeriod <= 28): break else: print 'Hire period must be between 1 and 28.' except: print "Invalid input. Try again." return hirePeriod def calculateHireCharge(hireReturn, hirePeriod): if hirePeriod <= 10: if (car.getModel() == 'Avensis') or (car.getModel() == 'Mondeo'): hireCharge = hirePeriod * 60.00 if (car.getModel() == 'Corolla') or (car.getModel() == 'Focus'): hireCharge = hirePeriod * 50.00 elif (10 < hirePeriod) and (hirePeriod <= 28): if (car.getModel() == 'Avensis') or (car.getModel() == 'Mondeo'): hireCharge = 500 + ((hirePeriod - 10) * 30.00) if (car.getModel() == 'Corolla') or (car.getModel() == 'Focus'): hireCharge = 400 + ((hirePeriod - 10) * 20.00) else: print "we shouldn't be here!" quit() return hireCharge fleetInfo() hireReturn = customerDetails() carInfo() carMakeInfo() carModelInfo() petrolCarInfo() dieselCarInfo() electricCarInfo() hybridCarInfo() availableCars = updateFleet(carChoice, hireReturn) if hireReturn == 'h': customer.hirePeriod = calculateHirePeriod(hireReturn) customer.hireCharge = calculateHireCharge(hireReturn, customer.hirePeriod) print 'Customer name:\t\t\t', customer.getName() if hireReturn == 'r': print 'Thanks for returning the car.' if hireReturn == 'h': print 'Make of car hired:\t\t', car.getMake() print 'Model of car hired:\t\t', car.getModel() # print 'Transmission of car hired:\t', Car.getTransmission() if carChoice == 'p': print 'Petrol type:\t\t\t', petrolCar.getPetrolType() if carChoice == 'd': print 'Has turbo?:\t\t\t', dieselCar.getDieselTurbo() if carChoice == 'e': print 'Fuel cell type:\t\t\t', electricCar.getFuelCells() if carChoice == 'h': print 'Regenerative braking system:\t', hybridCar.getHybridBrake() print 'Hire period (days):\t\t', customer.hirePeriod print 'Hire charge (euro):\t\t', customer.hireCharge
print print "Welcome to DBS car rental, we have the following types of cars in stock to offer." print from car import Car, PetrolCar, DieselCar, ElectricCar, HybridCar #We made that in our stock we have 40 cars, 4 different types, each type of the same make, model and specifications. #Petrol car details. carP = PetrolCar() carP.setMake("Volkswagen Beetle") carP.setColour("Blue") carP.setNumberCylinders(4) carP.setMileage(1000) print " Make of Petrol car is :" + carP.getMake() print " Colour of the car is :" + carP.getColour() print " Number of cylinders :" + str(carP.getNumberCylinders()) print " Mileage of Petrol car is :" + str(carP.getMileage()) print "_________________________________________" #Diesel car details. carD = DieselCar() carD.setMake("Audi Q7") carD.setColour("Silver") carD.setNumberCylinders(4) carD.setMileage(500) print " Make of Diesel car is :" + carD.getMake() print " Colour of the car is :" + carD.getColour() print " Number of cylinders :" + str(carD.getNumberCylinders()) print " Milegae of Diesel car is :" + str(carD.getMileage()) print "_________________________________________"
""" File Description: car rental application Student ID : 10543531 Student Name: Wenjuan Zhao Git hub: https://github.com/lulu0066/B8IT105.git """ import pandas as pd from car import Car, PetrolCar, DieselCar, ElectricCar, HybridCar from carRental import CarFleet dbsCarRental = CarFleet() myCar = Car() myCar.setColour('Silver') petrol = PetrolCar() petrol.setMake('Ford') petrol.setModel('Focus') petrol.setEngineSize('1.6') diesel = DieselCar() diesel.setMake('Renault') diesel.setModel('Clio') diesel.setEngineSize('1.5') electric = ElectricCar() electric.setMake('Nissan') electric.setModel('Leaf') electric.setNumberFuelCells('62KWH') hybrid = HybridCar()
def setUp(self): self.petrol = PetrolCar()
def create_current_stock(self): for i in range(20): self.electric_cars.append(ElectricCar()) for i in range(10): self.petrol_cars.append(PetrolCar())
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() car4.setColour('Red') print('The colour is: ' + car4.getColour()) car4.setMileage(150) car4.move(25) print('The mileage is ' + str(car4.getMileage())) + 'kms' car4.engineSize = '2.9' print 'The engine size is ' + car4.engineSize car4.setNumberOfFuelCylinders(3) print('The number of fuel cylinders is ' + str(car4.getNumberOfFuelCylinders()))
def test_petrol_car_cylinders(self): petrol_car = PetrolCar() self.assertEqual(1, petrol_car.getNumberCylinders()) petrol_car.setNumberCylinders(4) self.assertEqual(4, petrol_car.getNumberCylinders())
def test_petrol_car_petrol_type(self): petrol_car = PetrolCar() self.assertEqual('', petrol_car.getFuelType()) petrol_car.setFuelType('petrol') self.assertEqual('petrol', petrol_car.getFuelType())
class TestPetrolCar(unittest.TestCase): def setUp(self): # The PetrolCar class calls itself. self.petrol_car = PetrolCar() def test_PetrolCar_fuel_cylinders(self): # Testing a PetrolCar the default value of 3 is called from the base class Petrol Car and is tested to # ensure the base class PetrolCar functions are being correctly implemented. The setNumberOfFuelCylinders # in this case changes the default value from 3 to 7 this is tested and it has become 7 so is true. # This is similar to ElectricCar FuelCells implementation but with cylinders instead of cells. # The cylinders are tested with values for 2 and 5 which pass. self.assertEqual(3, self.petrol_car.getNumberOfFuelCylinders()) self.petrol_car.setNumberOfFuelCylinders(7) self.assertEqual(7, self.petrol_car.getNumberOfFuelCylinders()) self.petrol_car.setNumberOfFuelCylinders(2) self.assertEqual(2, self.petrol_car.getNumberOfFuelCylinders()) self.petrol_car.setNumberOfFuelCylinders(5) self.assertEqual(5, self.petrol_car.getNumberOfFuelCylinders()) def test_PetrolCar_mileage_and_move(self): # Ths function tests the mileage of the PetrolCar class. As in the other tests it starts with the default # value from the base class. Move is then called using the value 5 this is tested against the value # retrieved from getMileage which is now increased to 5 so it's true. It is increased by 12 to make 17, # tested by adding 0 still gives 17, tested adding a decimal 6.5 to get 23.5. self.assertEqual(0, self.petrol_car.getMileage()) self.petrol_car.move(5) self.assertEqual(5, self.petrol_car.getMileage()) self.petrol_car.move(12) self.assertEqual(17, self.petrol_car.getMileage()) self.petrol_car.move(0) self.assertEqual(17, self.petrol_car.getMileage()) self.petrol_car.move(6.5) self.assertEqual(23.5, self.petrol_car.getMileage()) def test_PetrolCar_make(self): # Testing make function for PetrolCar to ensure correctly inherited from base class Car. self.assertEqual(' ', self.petrol_car.getMake()) self.petrol_car.setMake('Ford') self.assertEqual('Ford', self.petrol_car.getMake()) self.petrol_car.setMake('Ford Focus') self.assertEqual('Ford Focus', self.petrol_car.getMake()) def test_PetrolCar_engineSize(self): # Testing engineSize for PetrolCar class. self.assertEqual(' ', self.petrol_car.getEngineSize()) self.petrol_car.setEngineSize(2.2) self.assertEqual(2.2, self.petrol_car.getEngineSize()) self.petrol_car.setEngineSize(2.6) self.assertEqual(2.6, self.petrol_car.getEngineSize()) def test_PetrolCar_colour_and_paint(self): # Testing colour and paint for PetrolCar Class self.assertEqual(' ', self.petrol_car.getColour()) self.petrol_car.paint('black') self.assertEqual('black', self.petrol_car.getColour()) self.petrol_car.setColour('dark blue') self.assertEqual('dark blue', self.petrol_car.getColour())