summaryrefslogtreecommitdiff
path: root/src/Q2/BonusOnSavings.java
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2019-05-05 19:57:14 -0600
committermokha <mokha@cisco.com>2019-05-05 19:57:14 -0600
commit7b4cb6a2eef3a0fcde7e998832427c73599e4a0a (patch)
tree75acc7cd8f3bd8a087e909db182c9e18a66879a1 /src/Q2/BonusOnSavings.java
parent99a28d2dba93642e89a62ecf905a3bd4f138318d (diff)
use the exact naming convention for directories described by instructor
Diffstat (limited to 'src/Q2/BonusOnSavings.java')
-rw-r--r--src/Q2/BonusOnSavings.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Q2/BonusOnSavings.java b/src/Q2/BonusOnSavings.java
new file mode 100644
index 0000000..41090ec
--- /dev/null
+++ b/src/Q2/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);
+ }
+}