Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/rental/RentalPriceCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down