Copy the following SimpleBankAccount class and use it as a base class:
Simple representation of a bank account
@author
@version
import java.text.NumberFormat;
public class SimpleBankAccount{
private double balance;
Constructor for objects of class SimpleBankAccount
public SimpleBankAccount(){
balance = 0.0;
}
Constructor for objects of class SimpleBankAccount
public SimpleBankAccount( double bal ){
balance = bal;
}
Add money to the balance
@param amount
@return
public void deposit( double amount ){
balance += amount;
}
Remove money from the balance
@param amount
@return
public boolean withdraw( double amount ){
if( balance - amount >= 0 ){
balance -= amount;
return true;
}else{
return false;
}
}
Get the balance
@return
public double getBalance(){
return balance;
}
Produces a string representation of the balance
@return
public String toString( ){
String balanceStr = NumberFormat.getCurrencyInstance().format( balance );
return "Balance: " + balanceStr + "\n";
}
}
Include at least two classes: CheckingAccount and SavingsAccount. The CheckingAccount needs to add a field to track the last process check number and the following method:
public boolean processCheck( int checkNum, double amount );
which returns false if checkNum has the same check number as the last check processed, otherwise it reduces the balance by amount and returns true.
Additionally, the SavingsAccount needs to have an interest rate and an applyInterest() method.
The following code should work and produce the output below:
Exercises the basic functionality of a Checking and SavingsAccount
@author
@version
public class AccountsDriver{
final public static double INTEREST_RATE = 0.01;
public static void main( String[] args ){
CheckingAccount checking = new CheckingAccount( 100.0 );
SavingsAccount savings = new SavingsAccount( 1000.0, INTEREST_RATE );
double monthlyExpenses = 756.34;
int electricBillCheckNum = 2123;
double electricBill = 60.34;
int registationCheckNum = 2124;
double registration = 50.00;
double dinnerMoney = 55.32;
double futureCar = 200.0;
double textbook = 90.0;
checking.deposit( monthlyExpenses );
checking.processCheck( electricBillCheckNum, electricBill );
checking.withdraw( dinnerMoney );
checking.processCheck( registationCheckNum, registration );
System.out.print( checking.toString() );
savings.deposit( futureCar );
savings.applyInterest( );
savings.withdraw( textbook );
System.out.print( savings.toString() );
}
}
Output:
Checking Account:
Balance: $690.68
Last processed check: 2124
Savings Account:
Balance: $1,122.00
APR: 1.0%
Make just the necessary changes to the code in SimpleBankAccount and AccountsDriver to complete the instructions.