Commit 108f7cf

mokha <mokha@cisco.com>
2019-05-09 00:18:15
add documentation
1 parent fba4041
Changed files (1)
src/Q5/EmployeeSavings.java
@@ -1,3 +1,11 @@
+/**
+ * Assignment 1, COMP268 Class: EmployeeSavings.java
+ *
+ * @description Represents an employee savings account.
+ * @author: mo khan Student ID: 3431709
+ * @date May 8, 2019
+ * @version 1.0
+ */
 package Q5;
 
 import Q1.*;
@@ -13,45 +21,96 @@ public class EmployeeSavings extends AddressBook {
   private double monthlyContribution;
   public static final double ANNUAL_INTEREST_RATE = 0.05;
 
+  /**
+   * Constructs an EmployeeSavings object with a randomly generated monthly contribution.
+   *
+   * @param firstName the first name of the runner
+   * @param lastName the last name of the runner
+   */
   public EmployeeSavings(String firstName, String lastName) {
     this(firstName, lastName, new Random().nextInt(800 - 100) + 100.0);
   }
 
+  /**
+   * Constructs an EmployeeSavings object
+   *
+   * @param firstName the first name of the runner
+   * @param lastName the last name of the runner
+   * @param monthlyContribution the monthly contribution to the savings account
+   */
   public EmployeeSavings(String firstName, String lastName, double monthlyContribution) {
     super(firstName, "", lastName);
     this.monthlyContribution = monthlyContribution;
     this.accountValue = predictBalanceAfterMonths(12);
   }
 
-  // what is d1, d2?
+  /**
+   * Constructs an EmployeeSavings object
+   *
+   * @param firstName the first name of the runner
+   * @param lastName the last name of the runner
+   * @param d1 unknown
+   * @param d2 unknown
+   */
   public EmployeeSavings(String firstName, String lastName, double[] d1, double[] d2) {
     super(firstName, "", lastName);
   }
 
+  /**
+   * Return the predicted value of the account after 12 months.
+   *
+   * @return the predicted account value after 12 months
+   */
   public double getAccountValue() {
     return this.accountValue;
   }
 
+  /**
+   * Return an array of the predicted interest earned for each month in the upcoming year.
+   *
+   * @return the predicted interest earned for each month
+   */
   public double[] getMonthlyInterests() {
     return this.monthlyInterests;
   }
 
+  /**
+   * Return an array of the predicted monthly savings earned for each month in the upcoming year.
+   *
+   * @return the predicted monthly savings earned for each month
+   */
   public double[] getMonthlySavings() {
     return this.monthlySavings;
   }
 
+  /**
+   * Return an array of the predicted interest earned for each month in the upcoming year.
+   *
+   * @return the predicted interest earned for each month
+   */
   public double[] calculateInterests() {
     this.monthlyInterests = new double[12];
     for (int i = 1; i <= 12; i++) this.monthlyInterests[i - 1] = predictInterestAfterMonths(i);
     return this.monthlyInterests;
   }
 
+  /**
+   * Return an array of the predicted monthly savings earned for each month in the upcoming year.
+   *
+   * @return the predicted monthly savings earned for each month
+   */
   public double[] generateMonthlySavings() {
     this.monthlySavings = new double[12];
     for (int i = 1; i <= 12; i++) this.monthlySavings[i - 1] = predictBalanceAfterMonths(i);
     return this.monthlySavings;
   }
 
+  /**
+   * Predicts the balance of an accounts after n months.
+   *
+   * @param months The # of months from now to predict a balance for.
+   * @return the predicted balance
+   */
   public double predictBalanceAfterMonths(int months) {
     double monthlyRate = ANNUAL_INTEREST_RATE / 12.0;
     double balance = 0;
@@ -62,12 +121,25 @@ public class EmployeeSavings extends AddressBook {
     return Math.round(balance * 1000) / 1000.0;
   }
 
+  /**
+   * Predicts the interest of an accounts after n months.
+   *
+   * @param months The # of months from now to predict the interest for.
+   * @return the predicted interest
+   */
   public double predictInterestAfterMonths(int months) {
-    return Math.round(
-            (predictBalanceAfterMonths(months) - (months * this.monthlyContribution)) * 1000)
-        / 1000.0;
+    double totalBalance = predictBalanceAfterMonths(months);
+    double totalContributions = (months * this.monthlyContribution);
+
+    return Math.round((totalBalance - totalContributions) * 1000) / 1000.0;
   }
 
+  /**
+   * Generates a report that can be printed to the console.
+   *
+   * @param accounts the list of accounts to print a statement for
+   * @return a string that represents a report for the accounts given.
+   */
   public static String getReport(EmployeeSavings[] accounts) {
     ArrayList<String> statement = new ArrayList<String>();
 
@@ -76,6 +148,11 @@ public class EmployeeSavings extends AddressBook {
     return String.join(System.lineSeparator(), statement);
   }
 
+  /**
+   * Returns The first name, and predicted account balance after 12 months.
+   *
+   * @return a string that represents a summary for an account.
+   */
   @Override
   public String toString() {
     Currency currency = Currency.getInstance(Locale.getDefault());