Commit 9cd1f6b
Changed files (2)
assignments
assignment1
src
main
java
ca
mokhan
assignment1
test
java
ca
mokhan
assignment1
assignments/assignment1/src/main/java/ca/mokhan/assignment1/EmployeeSavings.java
@@ -1,8 +1,10 @@
package ca.mokhan.assignment1;
-import java.util.Objects;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Currency;
+import java.util.Locale;
+import java.util.Objects;
import java.util.Random;
public class EmployeeSavings extends AddressBook
@@ -24,7 +26,7 @@ public class EmployeeSavings extends AddressBook
this.accountValue = predictBalanceAfterMonths(12);
}
- // what is d1, d2? These are not intention revealing variable names.
+ // what is d1, d2?
public EmployeeSavings(String firstName, String lastName, double[] d1, double[] d2) {
super(firstName, "", lastName);
}
@@ -54,9 +56,8 @@ public class EmployeeSavings extends AddressBook
double monthlyRate = ANNUAL_INTEREST_RATE / 12.0;
double balance = 0;
- for (int i = 0; i < months; i++) {
+ for (int i = 0; i < months; i++)
balance = (balance + this.monthlyContribution) * (1 + monthlyRate);
- }
return Math.round(balance * 1000) / 1000.0;
}
@@ -66,8 +67,20 @@ public class EmployeeSavings extends AddressBook
return Math.round((predictBalanceAfterMonths(months) - (months * this.monthlyContribution)) * 1000) / 1000.0;
}
- public static String getReport(EmployeeSavings[] savings)
+ public static String getReport(EmployeeSavings[] accounts)
+ {
+ ArrayList<String> statement = new ArrayList<String>();
+
+ for (EmployeeSavings account : accounts)
+ statement.add(account.toString());
+
+ return String.join(System.lineSeparator(), statement);
+ }
+
+ @Override
+ public String toString()
{
- return "";
+ Currency currency = Currency.getInstance(Locale.getDefault());
+ return String.format("%s %s%.2f", super.getFirstName(), currency.getSymbol(), this.getAccountValue());
}
}
assignments/assignment1/src/test/java/ca/mokhan/assignment1/EmployeeSavingsTest.java
@@ -65,4 +65,28 @@ public class EmployeeSavingsTest extends TestCase
assertEquals(201.252, subject.generateMonthlySavings()[1]);
assertEquals(302.507, subject.generateMonthlySavings()[2]);
}
+
+ public void testGetReport()
+ {
+ EmployeeSavings[] accounts = new EmployeeSavings[] {
+ new EmployeeSavings("Elena", "Brandon"),
+ new EmployeeSavings("Thomas", "Molson"),
+ new EmployeeSavings("Hamilton", "Winn"),
+ new EmployeeSavings("Suzie", "Sarandin"),
+ new EmployeeSavings("Philip", "Winne"),
+ new EmployeeSavings("Alex", "Trebok"),
+ new EmployeeSavings("Emma", "Pivoto"),
+ new EmployeeSavings("John", "Lenthen"),
+ new EmployeeSavings("James", "Lean"),
+ new EmployeeSavings("Jane", "Ostin"),
+ new EmployeeSavings("Emily", "Car"),
+ new EmployeeSavings("Daniel", "Hamshire"),
+ new EmployeeSavings("Neda", "Bazdar"),
+ new EmployeeSavings("Aaron", "Smith"),
+ new EmployeeSavings("Kate", "Hen")
+ };
+ String report = EmployeeSavings.getReport(accounts);
+ for (EmployeeSavings account : accounts)
+ assertTrue(report.contains(account.getFirstName()));
+ }
}