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
50 changes: 39 additions & 11 deletions src/rental/RentalPriceCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,64 @@ public class RentalPriceCalculator {
// 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 price(int age, int licence, int clazz, boolean acc, boolean acc2, boolean season) {
public double price(int driverAge, int driversLicenseAge, int carType, boolean accidentsCaused, boolean isHighSeason) {

if (age < 18) {
if (isUnderage(driverAge)) {
throw new IllegalArgumentException("Driver too young - cannot quote the price");
}
if (age <= 21 && clazz > 2) {
if (canRentOnlyClassOneCars(driverAge, carType)) {
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) {
double rentalprice = driverAge;

if (isCarLargeWithYoungDriverDuringHighSeason(driverAge, carType, isHighSeason)) {
rentalprice = rentalprice * 2;
}
if (licence < 1) {

if (isLicenseNew(driversLicenseAge)) {
throw new IllegalArgumentException("Driver must hold driving licence at least for one year. Can not rent a car!");
}

if (licence < 3) {
if (isLicenseStillFresh(driversLicenseAge)) {
rentalprice = rentalprice * 1.3;
}

if (acc == true && age < 30) {
if (youngerDrivreHasCausedAccidentsInLastYear(driverAge, accidentsCaused)) {
rentalprice += 15;
}

if (rentalprice > 1000) {
if (isRentalPriceTooHigh(rentalprice)) {
return 1000.00;
}
return rentalprice;
}

private boolean isRentalPriceTooHigh(double rentalprice) {
return rentalprice > 1000;
}

private boolean youngerDrivreHasCausedAccidentsInLastYear(int driverAge, boolean accidentsCaused) {
return accidentsCaused && driverAge < 30;
}

private boolean isLicenseStillFresh(int driversLicenseAge) {
return driversLicenseAge < 3;
}

private boolean isLicenseNew(int driversLicenseAge) {
return driversLicenseAge < 1;
}

private boolean isCarLargeWithYoungDriverDuringHighSeason(int driverAge, int carType, boolean isHighSeason) {
return carType >=4 && driverAge <= 25 && isHighSeason;
}

private boolean canRentOnlyClassOneCars(int driverAge, int carType) {
return driverAge <= 21 && carType > 2;
}

private boolean isUnderage(int driverAge) {
return driverAge < 18;
}
}