diff --git a/.idea/misc.xml b/.idea/misc.xml
index 0792e77..60fc35e 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/RefactoringAssignment.iml b/RefactoringAssignment.iml
index 7e880ab..454125c 100644
--- a/RefactoringAssignment.iml
+++ b/RefactoringAssignment.iml
@@ -24,5 +24,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/InsuranceCalculator.java b/src/InsuranceCalculator.java
index 558e0a0..46a3744 100644
--- a/src/InsuranceCalculator.java
+++ b/src/InsuranceCalculator.java
@@ -1,15 +1,23 @@
public class InsuranceCalculator {
+ private calculate strategy;
+
public double calculateInsurance(double income) {
+
+
if (income <= 10000) {
- return income*0.365;
+ strategy = new InsuranceStrategyLow();
+ return strategy.calculateInsuranceVeryHigh(income);
} else if (income <= 30000) {
- return (income-10000)*0.2+35600;
+ strategy = new InsuranceStrategyMedium();
+ return strategy.calculateInsuranceVeryHigh(income);
} else if (income <= 60000) {
- return (income-30000)*0.1+76500;
+ strategy = new InsuranceStrategyHigh();
+ return strategy.calculateInsuranceVeryHigh(income);
} else {
- return (income-60000)*0.02+105600;
+ strategy = new InsuranceStrategyVeryHigh();
+ return strategy.calculateInsuranceVeryHigh(income);
}
- }
-}
+ }
+}
\ No newline at end of file
diff --git a/src/InsuranceStrategyHigh.java b/src/InsuranceStrategyHigh.java
new file mode 100644
index 0000000..ee7b66c
--- /dev/null
+++ b/src/InsuranceStrategyHigh.java
@@ -0,0 +1,16 @@
+public class InsuranceStrategyHigh extends calculate {
+ @Override
+ public int getConstant() {
+ return 78500;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.04;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 50000;
+ }
+}
diff --git a/src/InsuranceStrategyLow.java b/src/InsuranceStrategyLow.java
new file mode 100644
index 0000000..4db3f33
--- /dev/null
+++ b/src/InsuranceStrategyLow.java
@@ -0,0 +1,16 @@
+public class InsuranceStrategyLow extends calculate {
+ @Override
+ public int getConstant() {
+ return 1825;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.05;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 5000;
+ }
+}
diff --git a/src/InsuranceStrategyMedium.java b/src/InsuranceStrategyMedium.java
new file mode 100644
index 0000000..19cbcf3
--- /dev/null
+++ b/src/InsuranceStrategyMedium.java
@@ -0,0 +1,16 @@
+public class InsuranceStrategyMedium extends calculate {
+ @Override
+ public int getConstant() {
+ return 38600;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.035;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 25000;
+ }
+}
diff --git a/src/InsuranceStrategyVeryHigh.java b/src/InsuranceStrategyVeryHigh.java
new file mode 100644
index 0000000..ee7ceac
--- /dev/null
+++ b/src/InsuranceStrategyVeryHigh.java
@@ -0,0 +1,20 @@
+public class InsuranceStrategyVeryHigh extends calculate {
+ public InsuranceStrategyVeryHigh() {
+ }
+
+ public double calculateInsuranceVeryHigh(double income) {
+ return (income - getAdjustment()) * getWeight() + getConstant();
+ }
+
+ public int getConstant() {
+ return 105600;
+ }
+
+ public double getWeight() {
+ return 0.02;
+ }
+
+ public int getAdjustment() {
+ return 60000;
+ }
+}
\ No newline at end of file
diff --git a/src/calculate.java b/src/calculate.java
new file mode 100644
index 0000000..c5fe41e
--- /dev/null
+++ b/src/calculate.java
@@ -0,0 +1,12 @@
+public abstract class calculate {
+
+ public double calculateInsuranceVeryHigh(double income) {
+ return (income - getAdjustment()) * getWeight() + getConstant();
+ }
+
+ public abstract int getConstant();
+
+ public abstract double getWeight();
+
+ public abstract int getAdjustment();
+}
\ No newline at end of file
diff --git a/test/EMPTY b/test/EMPTY
deleted file mode 100644
index e69de29..0000000
diff --git a/test/TestDemo.java b/test/TestDemo.java
new file mode 100644
index 0000000..541ae4a
--- /dev/null
+++ b/test/TestDemo.java
@@ -0,0 +1,27 @@
+import org.junit.Test;
+import static org.junit.Assert.*;
+public class TestDemo {
+ @Test
+ public void low() {
+ assertEquals(1825, insuranceFor(5000), 0.01);
+ }
+
+ @Test
+ public void medium() {
+ assertEquals(38600, insuranceFor(25000), 0.01);
+ }
+
+ @Test
+ public void high() {
+ assertEquals(78500, insuranceFor(50000), 0.01);
+ }
+
+ @Test
+ public void veryHigh() {
+ assertEquals(106400, insuranceFor(100_000), 0.01);
+ }
+
+ private double insuranceFor(double income) {
+ return new InsuranceCalculator().calculateInsurance(income);
+ }
+ }