Commit 5cdd780

mokha <mokha@cisco.com>
2019-05-04 15:54:39
use the instance variables because the assignment demands it.
1 parent 5bb100c
Changed files (2)
assignments
assignment1
src
main
java
ca
mokhan
test
java
ca
mokhan
assignments/assignment1/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java
@@ -1,23 +1,27 @@
 package ca.mokhan.assignment1;
 
 import java.util.Objects;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Random;
 
 public class EmployeeSavings extends AddressBook
 {
-  //private double accountValue;
-  //private double[] monthlyInterests;
-  //private double[] monthlySavings;
+  private double accountValue;
+  private double[] monthlyInterests;
+  private double[] monthlySavings;
   public static final double ANNUAL_INTEREST_RATE = 0.05;
 
   private double monthlyContribution;
 
   public EmployeeSavings(String firstName, String lastName) {
-    this(firstName, lastName, new double[12], new double[12]);
+    this(firstName, lastName, new Random().nextInt(800 - 100) + 100.0);
   }
 
   public EmployeeSavings(String firstName, String lastName, double monthlyContribution) {
     super(firstName, "", lastName);
     this.monthlyContribution = monthlyContribution;
+    this.accountValue = predictBalanceAfterMonths(12);
   }
 
   // what is d1, d2? These are not intention revealing variable names.
@@ -25,28 +29,25 @@ public class EmployeeSavings extends AddressBook
     super(firstName, "", lastName);
   }
 
-  public double getAccountValue() { return predictBalanceAfterMonths(12); }
+  public double getAccountValue() { return this.accountValue; }
+  public double[] getMonthlyInterests() { return this.monthlyInterests; }
+  public double[] getMonthlySavings() { return this.monthlySavings; }
+
   public double[] calculateInterests()
   {
-    return new double[] {
-      predictInterestAfterMonths(1),
-      predictInterestAfterMonths(2),
-      predictInterestAfterMonths(3),
-      predictInterestAfterMonths(4),
-      predictInterestAfterMonths(5),
-      predictInterestAfterMonths(6),
-      predictInterestAfterMonths(7),
-      predictInterestAfterMonths(8),
-      predictInterestAfterMonths(9),
-      predictInterestAfterMonths(10),
-      predictInterestAfterMonths(11),
-      predictInterestAfterMonths(12),
-    };
+    this.monthlyInterests = new double[12];
+    for (int i = 1; i <= 12; i++)
+      this.monthlyInterests[i-1] = predictInterestAfterMonths(i);
+    return this.monthlyInterests;
+  }
+
+  public double[] generateMonthlySavings()
+  {
+    this.monthlySavings = new double[12];
+    for (int i = 1; i <= 12; i++)
+      this.monthlySavings[i-1] = predictBalanceAfterMonths(i);
+    return this.monthlySavings;
   }
-  //public double[] generateMonthlySavings() { }
-  //public double[] getMonthlyInterests() {}
-  //public double[] getMonthlySavings() {}
-  //public static String getReport(EmployeeSavings[] savings) {}
 
   public double predictBalanceAfterMonths(int months)
   {
@@ -64,4 +65,9 @@ public class EmployeeSavings extends AddressBook
   {
     return Math.round((predictBalanceAfterMonths(months) - (months * this.monthlyContribution)) * 1000) / 1000.0;
   }
+
+  public static String getReport(EmployeeSavings[] savings)
+  {
+    return "";
+  }
 }
assignments/assignment1/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java
@@ -58,4 +58,11 @@ public class EmployeeSavingsTest extends TestCase
     assertEquals(27.886, subject.calculateInterests()[10]);
     assertEquals(33.002, subject.calculateInterests()[11]);
   }
+
+  public void testGenerateMonthlySavings()
+  {
+    assertEquals(100.417, subject.generateMonthlySavings()[0]);
+    assertEquals(201.252, subject.generateMonthlySavings()[1]);
+    assertEquals(302.507, subject.generateMonthlySavings()[2]);
+  }
 }