Question: Java only: In this lab, we are going to enhance the BankAccount problem. We will add a String instance variable named accountName and add two
Java only: In this lab, we are going to enhance the BankAccount problem. We will add a String instance variable named accountName and add two methods, one to get the accountName and one to pay fees.
1. Create a class named BankAccountPlus
2. Copy of type in the BankAccount class from Chapter 3 (this is below)
/**
A bank account has a balance that can be charged by deposits and withdrawals.
*/
public class BankAccount
{
private double balance;
/**
Constructs a bank account with a zero balance.
*/
public BankAccount()
{
balance= 0;
}
/**
Constructs a bank account with a given balance.
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{
balance= initialBalance;
}
/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
balance= balance + amount;
}
/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{
balance = balance - amount;
}
/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{
return balance;
}
}
3. Add an instance variable named accountName; keep the balance instance variable.
4. Chance both constructors. On the default constructor (the one that does not have an argument), add a String argument to hold the name of the owner of the account. Call it an and use it to initialize accountName.
5. Add a method that will return the accountName.
6. Add a method called payFees. This method will charge a monthly fee. The method has no arguments and does not return anything. The method should call the withdraw method to deduct five dollars from the account if the account has a balance less than $2000 or call the withdraw method to deduct ten dollars if the balance is greater than 2,000 and less than 20,000. If the account has a balance greater than 20,000 then do not deduct a fee.
7. Create a BankAccountPlusTester (this should be the main)
8. Import Scanner
9. Create a Scanner object
10. Create a name and balance local variable.
11. Create 3 BankAccountPlus objects by:
a. Ask the user for a name and add it to the variable name.
b. Ask the user for an opening balance and add it to the variable balance.
c. Create the account with the information provided from the user.
d. Dont forget you many need to add extra in.nextLine() like we did in a previous lab.
12. Create a fourth BankAccountPlus object that will have the name dummy and no balance.
13. Call payFees for each account.
14. Print the name and balance for each account. Be sure and use words to describe what each output means.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
