added solution with tariff options as enum and map
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.pfefferminzia.petinsurance.tariffs;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public enum AgeTariff {
|
||||
UP_TO_TWO(2, new BigDecimal("0.2")), UP_TO_FIVE(5, new BigDecimal("0.25")), UP_TO_SEVEN(7,
|
||||
new BigDecimal("0.28")), OVER_SEVEN(Integer.MAX_VALUE, new BigDecimal("0.3"));
|
||||
|
||||
private final int maxAge;
|
||||
|
||||
private final BigDecimal factor;
|
||||
|
||||
private AgeTariff(int maxAge, BigDecimal factor) {
|
||||
this.maxAge = maxAge;
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
public static BigDecimal getFactorForAge(int age) {
|
||||
for (AgeTariff rate : values()) {
|
||||
if (age <= rate.maxAge) {
|
||||
return rate.factor;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Unexpected age: " + age);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.pfefferminzia.petinsurance.tariffs;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
public final class BreedPremiumAdjustment {
|
||||
|
||||
private static final Map<String, BigDecimal> ADJUSTMENTS = Map.of(
|
||||
"Dackel", new BigDecimal("-0.1"),
|
||||
"Bernhardiner", new BigDecimal("0.1")
|
||||
);
|
||||
|
||||
public static BigDecimal forBreed(String breed) {
|
||||
return ADJUSTMENTS.getOrDefault(breed, BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
private BreedPremiumAdjustment() {}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.pfefferminzia.petinsurance.tariffs;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public enum Tariff {
|
||||
KOMPAKT(BigDecimal.ONE), OPTIMAL(BigDecimal.valueOf(1.2)), PREMIUM(BigDecimal.valueOf(1.4));
|
||||
KOMPAKT(BigDecimal.ONE), OPTIMAL(new BigDecimal("1.2")), PREMIUM(new BigDecimal("1.4"));
|
||||
|
||||
private final BigDecimal rate;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user