Question: Simple JAVA program, Please fill in the bolded italicized part. /** SavingsAccountMinimumTester -- to test the SavingsAccountMinimum class. See the SavingsAccountMinimum.java for the code that
Simple JAVA program, Please fill in the bolded italicized part.
/**
SavingsAccountMinimumTester -- to test the SavingsAccountMinimum class.
See the SavingsAccountMinimum.java for the code that your write.
Change nothing here.
*/
public class SavingsAccountMinimumTester
{
public static void main(String[] args)
{
SavingsAccountMinimum account ;
account = new SavingsAccountMinimum(10) ;
account.deposit(1000) ;
//addInterest after first deposit to initilize minimumBalance
account.addInterest() ;
System.out.println(account.getBalance()) ;
System.out.println("1000.0 WAS EXPECTED") ;
//this time the addinterest works with 1000 min balance
account.addInterest() ;
System.out.println(account.getBalance()) ;
System.out.println("1100.0 WAS EXPECTED") ;
account.withdraw(600) ;
//this time the addinterest works with 500 min balance
account.addInterest() ;
System.out.println(account.getBalance()) ;
System.out.println("550.0 WAS EXPECTED") ;
account = new SavingsAccountMinimum(10) ;
account.deposit(1000) ;
//addInterest after first deposit to initilize minimumBalance
account.addInterest() ;
account.withdraw(800) ;
account.deposit(800) ;
account.withdraw(0) ;
//this time addInterest will work with min balance of 200
account.addInterest() ;
System.out.println(account.getBalance()) ;
System.out.println("1020.0 WAS EXPECTED") ;
account = new SavingsAccountMinimum(10) ;
account.deposit(550) ;
//addInterest after first deposit to initilize minimumBalance
account.addInterest() ;
account.deposit(300.33) ;
account.withdraw(257.57) ;
account.withdraw(37.22) ;
account.addInterest() ;
System.out.printf("%.2f ", account.getBalance()) ;
}
}
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
class BankAccount
{
//instance variables
private double balance; //the money in the account
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance = 0;
}
/**
Constructs a bank account with a given balance.
@param aBalance the initial balance
*/
public BankAccount(double aBalance)
{
balance = aBalance;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
double newBalance = balance + amount;
balance = newBalance;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
double newBalance = balance - amount;
balance = newBalance;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
/**
Gives a string representation of the bankaccount,
but in this case the string is just the balance.
@return the balance as a string
*/
public String toString()
{
return "" + balance ;
}
}
/**
A savings account is a special bank account
that has an interest rate. The interest is calculated on a monthly
basis (that is when addInterest() is called, and it uses the current
balance at the end of the month for calculating the interest.
Note: interestRate is "protected" here so that it is accessible to the
subclass.
*/
class SavingsAccount extends BankAccount
{
//instance variables
protected double interestRate ;
/**
Constructs a savings account with given interest rate
@param rate the interest rate
*/
public SavingsAccount(double rate)
{
interestRate = rate ;
}
/**
Adds the earned interest to the account balance.
*/
public void addInterest()
{
double interest = getBalance() * interestRate / 100 ;
deposit(interest) ;
}
}
/**
A SavingsAccount is a special BankAccount with an interest rate.
A SavingsAccountMinimum is a subclass of SavingsAccount
where the interest is computed on the minimum balance
since the last call to addInterest. Therefore,
you have to modify SavingsAccountMinimum so that
it has an instance variable to remember the minimum balance, and
it has a different addInterest method (from the one in SavingsAccount).
You need to modify the withdraw method as well, since that is where
the balance goes down, which might affect the minimum balance.
Note that interestRate has access specifier "protected"
in SavingsAccount so that it is accessible in this subclass.
*/
class SavingsAccountMinimum extends SavingsAccount
{
//-----------Start below here. To do: approximate lines of code = 1
// 1. an instance variable. Hint: see constructor for the name
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
/**
Constructs a savings account with given interest rate
@param rate the interest rate
*/
public SavingsAccountMinimum(double rate)
{
super(rate) ;
minimumBalance = 0 ;
}
/**
Adds the earned interest to the account balance,
based on the MINIMUM balance (not the regular balance).
*/
public void addInterest()
{
//-----------Start below here. To do: approximate lines of code = 3
// 2. double interest = ...
//note: interestRate is a percent and is "protected" in SavingsAccount
//note: the interest depends on the minimum balance
//3. somehow add the interest to the balance,
//4. make minimumBalance be the current balance, since starting fresh
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Withdraws money from the account and updates minimum balance
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
//-----------Start below here. To do: approximate lines of code = 2
// Override the withdraw method.
//5. somehow to decrease balance by amount;
//6. update minimumBalance when the new balance is less than ever
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
