summaryrefslogtreecommitdiff
path: root/src/Q5/EmployeeSavings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Q5/EmployeeSavings.java')
-rw-r--r--src/Q5/EmployeeSavings.java184
1 files changed, 0 insertions, 184 deletions
diff --git a/src/Q5/EmployeeSavings.java b/src/Q5/EmployeeSavings.java
deleted file mode 100644
index e4b067d..0000000
--- a/src/Q5/EmployeeSavings.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/**
- * 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.*;
-import java.util.ArrayList;
-import java.util.Currency;
-import java.util.Locale;
-import java.util.Random;
-
-public class EmployeeSavings extends AddressBook {
- private double accountValue;
- private double[] monthlyInterests;
- private double[] monthlySavings;
- 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);
- }
-
- /**
- * 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;
-
- for (int i = 0; i < months; i++)
- balance = (balance + this.monthlyContribution) * (1 + monthlyRate);
-
- 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) {
- 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>();
-
- for (EmployeeSavings account : accounts) statement.add(account.toString());
-
- 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());
- return String.format(
- "%s %s%.2f", super.getFirstName(), currency.getSymbol(), this.getAccountValue());
- }
-
- public static void main(String[] args) {
- EmployeeSavings[] accounts = {
- 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")
- };
-
- System.out.print(EmployeeSavings.getReport(accounts));
- }
-}