diff --git a/src/rental/RentalPriceCalculator.java b/src/rental/RentalPriceCalculator.java index 43fdddf..30779b1 100644 --- a/src/rental/RentalPriceCalculator.java +++ b/src/rental/RentalPriceCalculator.java @@ -2,39 +2,40 @@ public class RentalPriceCalculator { - // age - age of driver - // licence - number of full years person holds driving licence - // clazz - class of the car from 1 (smallest) to 5 (largest) that person wishes to rent - // acc - has s/he caused any accidents within last year - // acc2 - has s/he participated (but not caused) in any accidents within last year + // driversAge - age of driver + // licenceForYears - number of full years person holds driving licence + // carClass - class of the car from 1 (smallest) to 5 (largest) that person wishes to rent + // causedAccidents - has s/he caused any accidents within last year // season - if it is high season or not - public double price(int age, int licence, int clazz, boolean acc, boolean acc2, boolean season) { - - if (age < 18) { + public double calculatePrice(int driversAge, int licenceForYears, int carClass, boolean causedAccidents, boolean season) { + double rentalPrice = driversAge; + checkDriversSuitability(driversAge, licenceForYears); + rentalPrice = getRentalPrice(driversAge, licenceForYears, carClass, causedAccidents, season); + return rentalPrice: + } + + public boolean checkDriversSuitability(int driversAge, int licenceForYears){ + if (driversAge < 18) { throw new IllegalArgumentException("Driver too young - cannot quote the price"); } - if (age <= 21 && clazz > 2) { + if (driversAge <= 21 && carClass > 2) { throw new UnsupportedOperationException("Drivers 21 y/o or less can only rent Class 1 vehicles"); } - - double rentalprice = age; - - if (clazz >=4 && age <= 25 && season != false) { - rentalprice = rentalprice * 2; - } - - if (licence < 1) { + if (licenceForYears < 1) { throw new IllegalArgumentException("Driver must hold driving licence at least for one year. Can not rent a car!"); } - - if (licence < 3) { + } + + public int getRentalPrice(int driversAge, int licenceForYears, int carClass, boolean causedAccidents, boolean season){ + if (carClass >=4 && driversAge <= 25 && season != false) { + rentalprice = rentalprice * 2; + } + if (licenceForYears < 3) { rentalprice = rentalprice * 1.3; } - - if (acc == true && age < 30) { + if (causedAccidents == true && driversAge < 30) { rentalprice += 15; } - if (rentalprice > 1000) { return 1000.00; }