Question: JAVA PLEASE PART 1 For some types of accounts, it is important to keep track of the minimum balance over a period. Also, some accounts
JAVA PLEASE
PART 1
For some types of accounts, it is important to keep track of the minimum balance over a period.
Also, some accounts have adjustments made on a periodic basis: monthly fees, interest earned
To implement tracking the minimum balance in BankAccount, make the following changes to the
class.
Instance field minBalance
A getter for minBalance: getMinBalance
Method resetMinBalance
No parameters Sets minBalance to the value of balance
Method updateMinBalance
No parameters If minBalance is greater than balance, sets minBalance to the value of balance
Any constructor will call resetMinBalance at the end
deposit and withdraw both call updateMinBalance at the end
PART 2
Some accounts have adjustments made on a periodic basis: monthly fees, interest earned. A new type of account is introduced
Add a method to carry out tasks that must be taken care of at the end of each month
Method month_end_process
public, can be used externally Calls resetMinBalance. Using this method at the end of each month means that the min balance is always the minimum balance during the past month
Create a new class SavingsAccount that extends BankAccount
There is an instance field, annualInterestRate
Provide constructors
The first constructor takes two parameters: the account id and the annual interest rate
The second constructor takes three parameters: the account id, the initial balance and the annual interest rate
Getter and setter for the annual interest rate
Override the monthly processing method
Add the interest earned that month to the account The amount of interest earned in a month is the mininum balance during the month times the monthly interest rate The monthly interest rate is the annual interest rate divided by 12 After adding interest to the account, call the monthly processing method in BankAccount.
PART 3
This part of the lab uses ArrayList to let customers of a bank have direct access to their own accounts. This part requires additions to the AccountOwner class.
Add a new instance field accountsOwned that is an ArrayList
Each constructor should initialize accountsOwned to an empty list
Add a getter for accountsOwned
Add a method named totalBalanceOfAccountsOwned that takes no parameters and returns the total balance of all accounts owned by that person
Add a method named ownerOfAllAccountsOwned that returns true if all the accounts in accountsOwned actually specify this Person as the owner. Otherwise, the method returns false.
EXISTING CODE TO BE MODIFIED (sorry i left this off)
public class BankAccount {
private double balance; // account balance private String accountId; // unique account identifier private AccountOwner owner; // owner of the account
/** * Initializes the account id to the parameter value and initializes * the balance to 0. * The owner of the account is set to null. * * @param initialAccountId Should be a valid account id. (can't check it at this time) */ public BankAccount(String initialAccountId) { accountId = initialAccountId; balance = 0.0; // not necessary since balance will default to 0.0 if nothing else is done // to initialize it.
}
/** * Initializes the account id and balance from the parameter values. * The owneer of the account is set to null; * * @param initialAccountId Should be a valid account id. (can't check it at this time) * @param initialBalance Should be positive */ public BankAccount(String initialAccountId, double initialBalance) { accountId = initialAccountId; if(initialBalance <= 0) { // error System.err.println("Initial balance for an account should be positive: " + initialBalance); System.exit(1); } else { balance = initialBalance; }
}
public BankAccount(String initialAccountid, double initialBalance, AccountOwner initialOwner) { accountId = initialAccountid; owner = initialOwner; if(initialBalance <= 0) { // error System.err.println("Initial balance for an account should be positive: " + initialBalance); System.exit(1); } else { balance = initialBalance; }
}
public String getAccountId() { return accountId; }
public double getBalance() { return balance; }
/** * Deposit the given amount in this bank account. * This will add amount to the balance. * * @param amount Should be a positive number, that is, greater than 0 */ public void deposit(double amount) { if(amount > 0) { // go ahead and process the deposit balance += amount; } else { // report an error System.err.println("Amount of deposit should be positive: " + amount); System.exit(1); }
}
/** * Withdraw the given amount from this bank account. * The amount will be deducted from the account balance. * * @param amount Should be a positive value. * Should be no bigger than the current balance. */ public void withdraw(double amount) { if(amount <= 0) { // error: amount should be positive System.err.println("Amount of withdrawal should be positive: " + amount); System.exit(1); } else if(amount > balance) { // error: amount should be no bigger than the balance System.err.println("Amount of withdrawal should be no bigger than the balance: " + amount + " " + balance); System.exit(1); } else { // amount is ok, process the withdrawal balance -= amount; }
}
public void setOwner(AccountOwner newOwner) { owner = newOwner; }
public AccountOwner getOwner() { return owner; }
}
------------------------------------------------------------------------------------
public class AccountOwner {
private String name;
private String accountOwnerId;
private String e_mail;
/**
* Initialize the properties of this object to the given parameter values.
* If a value is not known, use null.
*/
public AccountOwner(String name, String accountOwnerId, String e_mail) {
this.name = name;
this.accountOwnerId = accountOwnerId;
this.e_mail = e_mail;
}
public AccountOwner(String accountOwnerId) {
this.accountOwnerId = accountOwnerId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getE_mail() {
return e_mail;
}
public void setE_mail(String e_mail) {
this.e_mail = e_mail;
}
public String getAccountOwnerIdId() {
return accountOwnerId;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
