diff --git a/RentalPriceCalculator.java b/RentalPriceCalculator.java new file mode 100644 index 0000000..f56af53 --- /dev/null +++ b/RentalPriceCalculator.java @@ -0,0 +1,47 @@ +package rental; + +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 + // season - if it is high season or not + private int age; + private int licence; + private int clazz; + private boolean accidentsCaused; + private boolean season; + + RentalPriceCalculator(int age, int licence, int clazz, boolean accidentsCaused, boolean season){ + age = this.age; + licence = this.licence; + clazz = this.clazz; + accidentsCaused = this.accidentsCaused; + season = this.season; + } + + public double calculatePrice() { + double rentalprice = age; + + + if (age < 18) { + throw new IllegalArgumentException("Driver too young - cannot quote the price"); + }else if (age <= 21 && clazz > 2) { + throw new UnsupportedOperationException("Drivers 21 y/o or less can only rent Class 1 vehicles"); + }else if (clazz >=4 && age <= 25 && season == true) { + rentalprice = rentalprice * 2; + }else if (licence < 1) { + throw new IllegalArgumentException("Driver must hold driving licence at least for one year. Can not rent a car!"); + }else if (licence < 3) { + rentalprice = rentalprice * 1.3; + }else if (accidentsCaused == true && age < 30) { + rentalprice += 15; + }else if (rentalprice > 1000) { + return 1000.00; + }else{ + return rentalprice; + } + return rentalprice; + } +} \ No newline at end of file