Question: ----------------------------------------------------------------------------------------------------------------------------------------------------------------- /** Define a new class SavingsAccount, which is a subclass of BankAccount. */ public class SavingsAccount extends BankAccount { private double annualInterestRate; /** When

 ----------------------------------------------------------------------------------------------------------------------------------------------------------------- /** Define a new class SavingsAccount, which is a subclass

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

/** Define a new class SavingsAccount, which is a subclass of BankAccount. */ public class SavingsAccount extends BankAccount {

private double annualInterestRate;

/** When creating an new object,if no arguments provided, using this constructor to initialize it. @param none this method takes no argument @return this method does not return anything */ public SavingsAccount() { annualInterestRate = 0.0; }

/** When creating an new object,this constructor initializes the accountHolder,balance and annualInterestRate using the arguments @param accountHolder initializes the accountHolder @param startBalance initializes the balance @param annualInterestRate initializes the annualInterestRate @return this method does not return anything */ public SavingsAccount(Customer accountHolder, double startBalance, double annualInterestRate) { super(accountHolder, startBalance); this.setAnnualInterestRate(annualInterestRate); }

/** Using this method can access the annualInterestRate. @param none this method takes no argument @return deposit rate of one year */ public double getAnnualInterestRate() { return annualInterestRate; }

/** Using this method can update the annualInterestRate. @param annualInterestRate a new one year deposit rate @return this method does not return anything */ public void setAnnualInterestRate(double annualInterestRate) { if ((annualInterestRate = 0)) { this.annualInterestRate = annualInterestRate; } }

/** can use this method to deposit the monthly interest to the account @param none this method takes no argument @return this method does not return anything */ public void depositMonthlyInterest() { double monthlyInterest = ((annualInterestRate/100) * (this.getBalance())) / 12.0; this.deposit(monthlyInterest); } /** this method computes monthly fees and monthly interest @param none takes no argument @return the outcome depending on 3 cases. */ protected double getMonthlyFeesAndInterest(){ if (getBalance() > 0.0 && getBalance() >= 1000.0) return getBalance()*(getAnnualInterestRate()/100.0/12.0); else if (getBalance() > 0.0) return getBalance()*(getAnnualInterestRate()/100.0/12.0) - 5.0; return getBalance()*0.2; }

}

-----------------------------------------------------------------------------------------------------------------------------------

/** Class for customer data?name and id. */ public class Customer {

private String name; private int id = 0;

/** this constructor will be invoked when no argument given @param none no argument @return nothing */ public Customer() {

}

/** When creating an new object,this constructor initializes the name and customer's ID using the arguments @param name initializes name @param id initializes id @return this method doesn't return anything */ public Customer(String name, int id) { this.name = new String(name); this.id = id; }

/** When creating an new object,initializing name and customer's ID copying the data of other customer object @param oldCustomer a variable that represents the account owner, including information of name and ID @return this method doesn't return anything. */ public Customer(Customer oldCustomer) { name = new String(oldCustomer.getName()); id = oldCustomer.getID(); }

/** Using this method can access the customer's name. @param none this method takes no argument @return name */ public String getName() { return new String(name); }

/** Using this method can update the customer's name. @param customerName a new name @return this method doesn't return anything */ public void setName(String newName) { name = new String(newName); }

/** Using this method can access the id. @param none this method takes no argument @return customer's ID */ public int getID() { return id; }

/** Using this method can update the id. @param id a new customer's ID @return this method doesn't return anything */ public void setID(int id) { this.id = id; }

/** Using this method can get the information of name and id. @param none this method takes no argument @return the information of name and id */ public String toString() { return new String("Name of Customer: " + name + " CustomerID: " + id + " "); } }

--------------------------------------------------------------------------------------------------------------------------------------

import static java.lang.Math.abs; /** Define a new class ChequingAccount, which is a subclass of BankAccount. */ public class ChequingAccount extends BankAccount {

private double overdraftFee; private double overdraftAmount;

/** When creating an new object,this constructor initializes the transactionFee using the argument. @param transactionFee the expenses incurred in the course of doing things @return this method does not return anything */ public ChequingAccount(double transactionFee) { this.overdraftFee = transactionFee; }

/** When creating an new object,this constructor initializes the customer, startBalance and transactionFee using the arguments. @param accountHolder an account Holder @param startBalance Initial funding @param transactionFee the expenses incurred in the course of doing things @return this method does not return anything */ public ChequingAccount(Customer accountHolder, double startBalance, double transactionFee) { super(accountHolder, startBalance); this.setOverdraftFee(transactionFee); }

/** Using this method can access the OverdraftFee . @param none this method takes no argument @return overdraftFee */ public double getOverdraftFee() { return this.overdraftFee; }

/** Using this method can update the OverdraftFee. @param fee money @return this method doesn't return anything */ public void setOverdraftFee(double fee) { this.overdraftFee = fee; }

/** Using this method can access the overdraftAmount. @param none this method takes no argument @return overdraftAmount */ public double getOverdraftAmount() { return this.overdraftAmount; }

/** Using this method can update the overdraftAmount. @param overdraft the amount that is allowed to overdraft @return this method doesn't return anything */ public void setOverdraftAmount(double overdraft) { if (abs(overdraft) = -overdraft) { overdraftAmount = overdraft; } } }

/** Reduce the amount using this method @param amount amount of withdraw @return this method does not return anything */ public void withdraw(double amount) {

if (amount > this.getBalance()) { if (amount

if (amount 0.0) return 0.0; return getBalance()*0.2; }

}

------------------------------------------------------------------------------------------------------------------------------------

import static java.lang.Math.abs; /** create a class called BankAccount */ abstract class BankAccount { private double balance; private Customer accountHolder;

/** this constructor will be invoked when no argument given @param none no argument @return nothing */ public BankAccount() { }

/** when creating a new object, this constructor initializes accountHolder and balance @param accountHolder initializes accountHolder @param startBalance initializes balance @return nothing */ public BankAccount(Customer accountHolder, double startBalance) { this.accountHolder = new Customer(accountHolder); this.balance = startBalance; } /** when creating a new object, this constructor initializes balance @param startBalance initializes balance @return nothing */ public BankAccount(double startBalance) { this.balance = startBalance; this.accountHolder = new Customer("", 0); }

/** using this method can access balance @param none method takes no argument @return balance */ public double getBalance() { return this.balance; } /** using this method can add balance @param amount amount of deposit @return nothing */ public void deposit(double amount) { if ((amount > 0) && (amount

/** using this method can decrease balance @param amount amount of withdraw @return nothing */ public void withdraw(double amount) { if ((amount

} } /** using this method can transfer money from BankAccount to account @param amount amount of withdraw and deposit @param toAccount another account @return nothing */ public void transfer(double amount, BankAccount toAccount) { double temp = this.balance; double delta = 0.000001;

this.withdraw(amount); if ((this.balance = temp - delta)) { return; } else { toAccount.deposit(amount); } }

/** using this method can update balance @param amount amount of balance @return nothing */ protected void setBalance(double amount) { this.balance = amount; }

/** using this method can access customer @param none @return clone */ public Customer getCustomer() { Customer clone = new Customer(this.accountHolder.getName(), this.accountHolder.getID()); return clone; } protected abstract double getMonthlyFeesAndInterest(); public void monthEndUpdate(){ setBalance(balance + getMonthlyFeesAndInterest()); }

}

----------------------------------------------------------------------------------------------------------------------

Requirements To be able to work on this assignment, you will need a functional version of the BankAccount class, Customer class, SavingAccount class from last week's assignment. Your first task is to get this working. Updated requirements for SavingsAccount Update the SavingAccount class such that Make annuallnterestRate static Add a static setter method to set the annuallnterestRate Update the constructor accordingly keeping in mind the static nature of annuallnterestRate (Should we give annuallnterestRate as argument each time we create an instance of SavingAccount?) SavingAccount class should pass the provided test cases. Updated requirements for Customer Update the Customer class such that it is immutable. Keeping in mind the immutable nature of Customer class, answer the following: Q. Why don't we need to worry about privacy leaks with respect to the accountHolder instance variable in BankAccount

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!