From daea9597e5fbfa6ae9be5e5024a0ddf7c8b344f5 Mon Sep 17 00:00:00 2001 From: Tanel123 Date: Wed, 29 Mar 2017 15:21:00 +0300 Subject: [PATCH 1/2] 9ndala tunnitoo --- RentalPriceCalculator.java | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 RentalPriceCalculator.java diff --git a/RentalPriceCalculator.java b/RentalPriceCalculator.java new file mode 100644 index 0000000..6f34d0b --- /dev/null +++ b/RentalPriceCalculator.java @@ -0,0 +1,46 @@ +package rental; + +public class RentalPriceCalculator { + 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 = age; + licence = licence; + clazz = clazz; + accidentsCaused = accidentsCaused; + season = season; + } + + // 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 + 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; + } + } +} \ No newline at end of file From 282323e7a846c8d711593711831431e4a53c60ee Mon Sep 17 00:00:00 2001 From: Tanel123 Date: Wed, 29 Mar 2017 15:33:29 +0300 Subject: [PATCH 2/2] =?UTF-8?q?9.=20n=C3=A4dala=20tunnit=C3=B6=C3=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tiim FITT --- RentalPriceCalculator.java | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/RentalPriceCalculator.java b/RentalPriceCalculator.java index 6f34d0b..f56af53 100644 --- a/RentalPriceCalculator.java +++ b/RentalPriceCalculator.java @@ -1,6 +1,12 @@ package rental; -public class RentalPriceCalculator { +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; @@ -8,19 +14,13 @@ public class RentalPriceCalculator { private boolean season; RentalPriceCalculator(int age, int licence, int clazz, boolean accidentsCaused, boolean season){ - age = age; - licence = licence; - clazz = clazz; - accidentsCaused = accidentsCaused; - season = season; + age = this.age; + licence = this.licence; + clazz = this.clazz; + accidentsCaused = this.accidentsCaused; + season = this.season; } - // 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 public double calculatePrice() { double rentalprice = age; @@ -42,5 +42,6 @@ public double calculatePrice() { }else{ return rentalprice; } + return rentalprice; } } \ No newline at end of file