summaryrefslogtreecommitdiff
path: root/src/section-2
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2019-05-05 19:48:09 -0600
committermokha <mokha@cisco.com>2019-05-05 19:48:09 -0600
commit99a28d2dba93642e89a62ecf905a3bd4f138318d (patch)
treeee10a7df683642a42991896bbec5ced501a2abd1 /src/section-2
parent3c2be35d16d7482442911f5b06b68512f86e15b5 (diff)
split code into directories closer to what the instructor wants
Diffstat (limited to 'src/section-2')
-rw-r--r--src/section-2/BonusOnSavings.java36
-rw-r--r--src/section-2/BonusOnSavingsTest.java26
2 files changed, 62 insertions, 0 deletions
diff --git a/src/section-2/BonusOnSavings.java b/src/section-2/BonusOnSavings.java
new file mode 100644
index 0000000..41090ec
--- /dev/null
+++ b/src/section-2/BonusOnSavings.java
@@ -0,0 +1,36 @@
+package ca.mokhan.assignment1;
+
+public class BonusOnSavings {
+ double annualRate = 0.0;
+ double quarterlyRate = 0.0;
+
+ public BonusOnSavings() {
+ this(0.03, 0.05);
+ }
+
+ public BonusOnSavings(double quarterlyRate, double annualRate) {
+ this.quarterlyRate = quarterlyRate;
+ this.annualRate = annualRate;
+ }
+
+ public double computeBonus(double monthlyCommitment, double q1, double q2, double q3, double q4) {
+ double quarterlyTarget = monthlyCommitment * 3;
+ double annualTarget = monthlyCommitment * 12;
+
+ return this.quarterlyBonus(quarterlyTarget, q1)
+ + this.quarterlyBonus(quarterlyTarget, q2)
+ + this.quarterlyBonus(quarterlyTarget, q3)
+ + this.quarterlyBonus(quarterlyTarget, q4)
+ + this.annualBonus(annualTarget, q1 + q2 + q3 + q4);
+ }
+
+ private double quarterlyBonus(double target, double actual) {
+ return (actual >= target) ? actual * this.quarterlyRate : 0.0;
+ }
+
+ private double annualBonus(double target, double actual) {
+ if (actual < target) return 0.0;
+
+ return (actual * this.annualRate) + ((actual - target) * 0.25);
+ }
+}
diff --git a/src/section-2/BonusOnSavingsTest.java b/src/section-2/BonusOnSavingsTest.java
new file mode 100644
index 0000000..e19d447
--- /dev/null
+++ b/src/section-2/BonusOnSavingsTest.java
@@ -0,0 +1,26 @@
+package ca.mokhan.assignment1;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class BonusOnSavingsTest extends TestCase {
+ private BonusOnSavings subject;
+
+ public BonusOnSavingsTest(String testName) {
+ super(testName);
+ this.subject = new BonusOnSavings();
+ }
+
+ public static Test suite() {
+ return new TestSuite(BonusOnSavingsTest.class);
+ }
+
+ public void testComputeBonusEmployeeOne() {
+ assertEquals(1650.00, subject.computeBonus(2000, 5000, 7000, 4000, 8000));
+ }
+
+ public void testComputeBonusEmployeeTwo() {
+ assertEquals(4680.00, subject.computeBonus(3000, 6000, 9000, 10000, 17000));
+ }
+}