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()
def setUp(self): """TestCarFleet setup""" try: self.__data = pandas.read_csv('carstock.csv') # print(self.__data) self.__car_fleet = CarFleet() # print("Filling cars fleet") for car_data in self.__data.itertuples(): # print car_data car = Car(car_data.Make, car_data.Model, car_data.Year, car_data.Size, car_data.Body_Type, car_data.Door_No, car_data.Capacity, car_data._8, car_data._9) self.assertEqual(car_data.Make, car.getMake()) self.assertEqual(car_data.Model, car.getModel()) self.assertEqual(car_data.Year, car.getYear()) self.assertEqual(car_data.Size, car.getSize()) self.assertEqual(car_data.Body_Type, car.getBodyType()) self.assertEqual(car_data.Door_No, car.getDoorNo()) self.assertEqual(car_data.Capacity, car.getCapacity()) self.assertEqual(car_data._8, car.getEngine()) self.assertEqual(car_data._9, car.getTransmition()) fleet_size = self.__car_fleet.getNumAvailable() self.__car_fleet.registerCar(car) self.assertEquals(fleet_size + 1, self.__car_fleet.getNumAvailable()) except NameError as ex: print("\n") print("WARNING: pandas lib is required to load csv files") print("no cars data will be loaded!\n") except Exception: print("\n") print("WARNING: carstock.csv not found.") import os dir_path = os.path.dirname(os.path.realpath(__file__)) print(" Make sure to coping it in: " + dir_path + os.path.sep + "carstock.csv") print("no cars data was loaded!\n")
def process_returnCar(self): answer = raw_input(' would you like to return a car? Yes: "Y", No: "N" : ') if answer == 'y': answer = raw_input(' what car are you returning? Petrol: "p" , Electric: "e" , Diesel: "d" , Hybrid: "h" : ') amount = int(raw_input(' how many are you returning? ')) new_mileage = int(raw_input(' what is the new mileage on your car: ')) if answer == 'p': self.return_car(self.petrol_cars, amount) elif answer == 'e': self.return_car(self.electric_cars, amount) elif answer == 'h': self.return_car(self.hybrid_cars,amount) else: self.return_car(self.diesel_cars, amount) return new_mileage car_fleet = CarFleet() car_fleet.returnCar(amount) if answer == 'n': self.process_rental() self.stock_count()
def test_car_fleet(self): car_fleet = CarFleet() self.assertEqual(40, car_fleet.getNumAvailable()) car_fleet.rentCar(20) self.assertEqual(20, car_fleet.getNumAvailable()) car_fleet.returnCar(5) self.assertEqual(25, car_fleet.getNumAvailable()) car_fleet.returnCar(5) self.assertEqual(30, car_fleet.getNumAvailable()) car_fleet.rentCar(7) self.assertEqual(23, car_fleet.getNumAvailable()) car_fleet.returnCar(10) car_fleet.rentCar(33)
def test_car_fleet(self): car_fleet = CarFleet() self.assertEqual(0, car_fleet.getProfit()) self.assertEqual(40, car_fleet.getNumAvailable()) car_fleet.rentCar(5) self.assertEqual(100, car_fleet.getProfit()) self.assertEqual(35, car_fleet.getNumAvailable()) car_fleet.returnCar(2) self.assertEqual(37, car_fleet.getNumAvailable()) car_fleet.returnCar(3) self.assertEqual(40, car_fleet.getNumAvailable()) car_fleet.returnCar(3) car_fleet.rentCar(50)
class TestCarFleet(unittest.TestCase): #Test car fleet functionality def setUp(self): #TestCarFleet setup try: self.__data = pandas.read_csv('carstock.csv') # print(self.__data) self.__car_fleet = CarFleet(); # print("Filling cars fleet") for car_data in self.__data.itertuples(): # print car_data car = Car(car_data.Make, car_data.Model, car_data.Year, car_data.Size, car_data.Body_Type, car_data.Door_No, car_data.Capacity, car_data._8 , car_data._9) self.assertEqual(car_data.Make, car.getMake()) self.assertEqual(car_data.Model, car.getModel()) self.assertEqual(car_data.Year, car.getYear()) self.assertEqual(car_data.Size, car.getSize()) self.assertEqual(car_data.Body_Type, car.getBodyType()) self.assertEqual(car_data.Door_No, car.getDoorNo()) self.assertEqual(car_data.Capacity, car.getCapacity()) self.assertEqual(car_data._8, car.getEngine()) self.assertEqual(car_data._9, car.getTransmition()) fleet_size = self.__car_fleet.getNumAvailable(); self.__car_fleet.registerCar(car) self.assertEquals(fleet_size + 1, self.__car_fleet.getNumAvailable()) except NameError as ex: print("\n") print("WARNING: pandas lib is required to load csv files") print("no cars data was be loaded!\n") except Exception: print("\n") print("WARNING: carstock.csv not found.") import os dir_path = os.path.dirname(os.path.realpath(__file__)) print(" be sure of coping it in: " + dir_path + os.path.sep + "carstock.csv") print("no cars data was be loaded!\n") # print(self.__car_fleet) def test_rent_return_one_car(self): #Rent and return one car available = self.__car_fleet.getNumAvailable(); rented = self.__car_fleet.getNumRented(); profit = self.__car_fleet.getProfit(); rent_index = self.__car_fleet.rentCar(0) self.assertEqual(available - 1, self.__car_fleet.getNumAvailable()) self.assertEqual(rented + 1, self.__car_fleet.getNumRented()) self.assertEqual(profit + 20, self.__car_fleet.getProfit()) self.__car_fleet.returnCar(rent_index); self.assertEqual(available, self.__car_fleet.getNumAvailable()) self.assertEqual(rented, self.__car_fleet.getNumRented()) def test_rent_all_cars(self): #Rent all cars and one more while self.__car_fleet.getNumAvailable() > 0: available = self.__car_fleet.getNumAvailable(); rented = self.__car_fleet.getNumRented(); profit = self.__car_fleet.getProfit(); self.__car_fleet.rentCar(0) self.assertEqual(available - 1, self.__car_fleet.getNumAvailable()) self.assertEqual(rented + 1, self.__car_fleet.getNumRented()) self.assertEqual(profit + 20, self.__car_fleet.getProfit()) # and one more result = self.__car_fleet.rentCar(0) # print (result) self.assertEqual("Sorry nothing to rent, please try again", result)
try: import pandas except ImportError: print( "\nERROR: pandas lib not installed!\n Install it by running 'pip install pandas'\n" ) from car import Car, CarFleet, ElectricCar car_fleet = CarFleet() # car_fleet.rentCar(5) # car_fleet.returnCar(2) # car_fleet.returnCar(3) try: data = pandas.read_csv('carstock.csv') # print("Filling cars fleet") for car_data in data.itertuples(): # print car_data car = Car(car_data.Make, car_data.Model, car_data.Year, car_data.Size, car_data.Body_Type, car_data.Door_No, car_data.Capacity, car_data._8, car_data._9) car_fleet.registerCar(car) except NameError as ex: print("\n") print("WARNING: pandas lib is required to load csv files") print("No car data was loaded!\n") except Exception: print("\n") print("WARNING: carstock.csv not found.")
total = 0 if selection == 'p' and total < 20: self.returns(self.petrol_cars, (total - quantity)) elif selection == 'd' and total < 8: self.returns(self.diesel_cars, (total - quantity)) elif selection == 'h' and total < 8: self.returns(self.hybrid_cars, (total - quantity)) elif selection == 'e' and total < 4: self.returns(self.electric_cars, (total - quantity)) self.stock_count() #Allow users to continue or exit the program dbs_car_rental = DBS_Car_Rental() dbs_car_rental.current_stock() proceed = 'y' while proceed == 'y': dbs_car_rental.process_rental() proceed = raw_input('Enter y to continue or n to quit: ') # Testing rentals and returns, see results in test_car.py file car_fleet = CarFleet() car_fleet.rentCar(5) car_fleet.returnCar(2) car_fleet.returnCar(3) car_fleet.rentCar(7) car_fleet.returnCar(3) car_fleet.rentCar(36)
# -*- coding: utf-8 -*- """ Course/module: HDip / B8IT105 - Programming for Big Data Student: Gerard Keaty Student Id: 10544675 Lecturer: Darren Redmond Task : CA2 - Car Rental app """ from car import ElectricCar, PetrolCar, HybridCar, DieselCar, CarFleet, Number europcar = CarFleet() europcar.readFleet() europcar.checkCarsInStock() europcar.mainMenu() europcar.getPetrolCars() europcar.changeStatus() europcar.write_to_csv()
def test_carFleet(self): car_fleet = CarFleet() self.assertEqual([], car_fleet.getPetrolCars()) self.assertEqual([], car_fleet.getElectricCars()) self.assertEqual([], car_fleet.getHybridCars()) self.assertEqual([], car_fleet.getHybridCars())