diff --git a/RefactoringAssignment.iml b/RefactoringAssignment.iml
index 7e880ab..a2c2215 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
deleted file mode 100644
index 558e0a0..0000000
--- a/src/InsuranceCalculator.java
+++ /dev/null
@@ -1,15 +0,0 @@
-public class InsuranceCalculator {
-
- public double calculateInsurance(double income) {
- if (income <= 10000) {
- return income*0.365;
- } else if (income <= 30000) {
- return (income-10000)*0.2+35600;
- } else if (income <= 60000) {
- return (income-30000)*0.1+76500;
- } else {
- return (income-60000)*0.02+105600;
- }
- }
-
-}
diff --git a/src/ifs/InsuranceCalculator.java b/src/ifs/InsuranceCalculator.java
new file mode 100644
index 0000000..c7d316f
--- /dev/null
+++ b/src/ifs/InsuranceCalculator.java
@@ -0,0 +1,21 @@
+package ifs;
+
+public class InsuranceCalculator {
+
+ private InsuranceStrategy strategy;
+ public double calculateInsurance(double income) {
+ if (income <= 10000) {
+ strategy = new InsuranceStrategyLow();
+ return strategy.calculateInsurance(income);
+ } else if (income <= 30000) {
+ strategy = new InsuranceStrategyMedium();
+ return strategy.calculateInsurance(income);
+ } else if (income <= 60000) {
+ strategy = new InsuranceStrategyHigh();
+ return strategy.calculateInsurance(income);
+ } else {
+ strategy = new InsuranceStrategyVeryHigh();
+ return strategy.calculateInsurance(income);
+ }
+ }
+}
diff --git a/src/ifs/InsuranceStrategy.java b/src/ifs/InsuranceStrategy.java
new file mode 100644
index 0000000..75061a9
--- /dev/null
+++ b/src/ifs/InsuranceStrategy.java
@@ -0,0 +1,13 @@
+package ifs;
+
+public abstract class InsuranceStrategy {
+ public double calculateInsurance(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/src/ifs/InsuranceStrategyHigh.java b/src/ifs/InsuranceStrategyHigh.java
new file mode 100644
index 0000000..0c3fd99
--- /dev/null
+++ b/src/ifs/InsuranceStrategyHigh.java
@@ -0,0 +1,18 @@
+package ifs;
+
+public class InsuranceStrategyHigh extends InsuranceStrategy {
+ @Override
+ public int getConstant() {
+ return 76500;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.1;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 30000;
+ }
+}
\ No newline at end of file
diff --git a/src/ifs/InsuranceStrategyLow.java b/src/ifs/InsuranceStrategyLow.java
new file mode 100644
index 0000000..4609fcc
--- /dev/null
+++ b/src/ifs/InsuranceStrategyLow.java
@@ -0,0 +1,18 @@
+package ifs;
+
+public class InsuranceStrategyLow extends InsuranceStrategy {
+ @Override
+ public int getConstant() {
+ return 0;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.365;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 0;
+ }
+}
\ No newline at end of file
diff --git a/src/ifs/InsuranceStrategyMedium.java b/src/ifs/InsuranceStrategyMedium.java
new file mode 100644
index 0000000..7f97923
--- /dev/null
+++ b/src/ifs/InsuranceStrategyMedium.java
@@ -0,0 +1,18 @@
+package ifs;
+
+public class InsuranceStrategyMedium extends InsuranceStrategy {
+ @Override
+ public int getConstant() {
+ return 35600;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.2;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 10000;
+ }
+}
\ No newline at end of file
diff --git a/src/ifs/InsuranceStrategyVeryHigh.java b/src/ifs/InsuranceStrategyVeryHigh.java
new file mode 100644
index 0000000..3ad4d5a
--- /dev/null
+++ b/src/ifs/InsuranceStrategyVeryHigh.java
@@ -0,0 +1,21 @@
+package ifs;
+
+public class InsuranceStrategyVeryHigh extends InsuranceStrategy{
+ public InsuranceStrategyVeryHigh() {
+ }
+
+ @Override
+ public int getConstant() {
+ return 105600;
+ }
+
+ @Override
+ public double getWeight() {
+ return 0.02;
+ }
+
+ @Override
+ public int getAdjustment() {
+ return 60000;
+ }
+}
\ No newline at end of file
diff --git a/test/ifs/IfElseDemoTest.java b/test/ifs/IfElseDemoTest.java
new file mode 100644
index 0000000..84b91fc
--- /dev/null
+++ b/test/ifs/IfElseDemoTest.java
@@ -0,0 +1,32 @@
+package ifs;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class IfElseDemoTest {
+ @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);
+ }
+
+}
\ No newline at end of file