From 4cbaffe1c5f5c0806ae864110994e8813a24314f Mon Sep 17 00:00:00 2001 From: mokha Date: Tue, 7 May 2019 09:18:55 -0600 Subject: document the BonusOnSavings class --- src/Q2/BonusOnSavings.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/Q2/BonusOnSavings.java') diff --git a/src/Q2/BonusOnSavings.java b/src/Q2/BonusOnSavings.java index d2e8199..1a0bb2e 100644 --- a/src/Q2/BonusOnSavings.java +++ b/src/Q2/BonusOnSavings.java @@ -1,18 +1,43 @@ +/** + * Assignment 1, COMP268 Class: BonusOnSavings.java + * + * @description Represents an object that can compute a bonus based on the amount an employee saves. + * @author: mo khan Student ID: 3431709 + * @date May 7, 2019 + * @version 1.0 + */ package Q2; public class BonusOnSavings { double annualRate = 0.0; double quarterlyRate = 0.0; + /** Constructs a BonusOnSavings with a default quarterly rate of 3% and annual rate of 5%. */ public BonusOnSavings() { this(0.03, 0.05); } + /** + * Constructs a BonusOnSavings object for a given income and marital status, and computes the tax. + * + * @param quarterlyRate the quarterly rate to apply. + * @param annualRate the annual rate to apply. + */ public BonusOnSavings(double quarterlyRate, double annualRate) { this.quarterlyRate = quarterlyRate; this.annualRate = annualRate; } + /** + * Computes the bonus based on the target monthly commitment and the actual quarterly + * contributions. + * + * @param q1 the actual contribution for the first quarter. + * @param q2 the actual contribution for the second quarter. + * @param q3 the actual contribution for the third quarter. + * @param q4 the actual contribution for the fourth quarter. + * @return the calculated bonus amount for the year. + */ public double computeBonus(double monthlyCommitment, double q1, double q2, double q3, double q4) { double quarterlyTarget = monthlyCommitment * 3; double annualTarget = monthlyCommitment * 12; @@ -24,10 +49,25 @@ public class BonusOnSavings { + this.annualBonus(annualTarget, q1 + q2 + q3 + q4); } + /** + * Computes the quarterly bonus for a given target and actual contribution amount. + * + * @param target the target quarterly contribution amount for this employee. + * @param actual the actual quarterly contribution amount for this employee. + * @return the calculated quarterly bonus + */ private double quarterlyBonus(double target, double actual) { return (actual >= target) ? actual * this.quarterlyRate : 0.0; } + /** + * Calculates the annual bonus amount for the target annual contribution and the actual + * contribution. + * + * @param target the target annual contribution + * @param actual the actual contribution amount for the year + * @return the calculated annual bonus + */ private double annualBonus(double target, double actual) { if (actual < target) return 0.0; -- cgit v1.2.3