Create a java program that tests the implementation of all the classes. Before doing transaction, user should be prompted the type of his bank account:  Savings or Checking.  This is in a form of menu.  After indicating the account type,  user should be prompted to select transaction from a menu:  deposit, withdraw, Inquire, or transfer.  To check the implementation of addPeriodicInterest in Savings account, add the method MonthEnd() in your program.  This method should be called so that interest be added to the balance of this saving account at the end of the month. Design your program such that all methods in both child class and parent class are tested. To make your program more realistic, your program should allow user do transactions until no more transactions needed.  Use a loop statement for this process

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Create a java program that tests the implementation of all the classes. Before doing transaction, user should be prompted the type of his bank account:  Savings or Checking.  This is in a form of menu.  After indicating the account type,  user should be prompted to select transaction from a menu:  deposit, withdraw, Inquire, or transfer.  To check the implementation of addPeriodicInterest in Savings account, add the method MonthEnd() in your program.  This method should be called so that interest be added to the balance of this saving account at the end of the month. Design your program such that all methods in both child class and parent class are tested.

To make your program more realistic, your program should allow user do transactions until no more transactions needed.  Use a loop statement for this process

 

ps. attached pictures are the lessons it might help

Bank Account Class
For our first example, we considered the basic BankAccount Class. Basically, it has an instance variable balance that holds the current balance. We can also provide two constructors: the first creates a
new account with a balance of 0.00, the second takes in an initialBalance and uses that for the initial balance.
The BankAccount class also has a set of useful methods other than the setter and getter methods:
public void deposit(double amount)
public void withdraw(double amount)
public double inquire()
I will no longer discuss the functionalities of these methods. Of course, these methods do what is expected. But I would like to include another method which is defined as follows:
public void transfer(BankAccount other, double amount) {
balance -- amount,
other.balance += amount;
(Notice that a method may refer to private instance variables of another object in the same class. This capability has nothing to do with inheritance, but it's good to remember that methods of a class
can always access instance variables of any object in the class for which they have a reference, not just the object referenced by this.)
This method is used when an account transfers an amount to another account. You noticed from the implementation of that the an amount is deducted from the balance and the same amount is
added to the other balance.
Other Bank Accounts
Banks offer many kinds accounts. A savings account pays periodic interest. A checking account pays no interest and may have transaction fees for deposits and withdrawals. A time deposit account
may have an interest penalty for early withdrawal. We could write a separate class for each of these variants of bank accounts. All of these different accounts have a balance, and they all have to deal
with deposits, withdrawals, getting the account balance, and transfers.
It is this situation that inheritance need to deal with it. The goal is to "inherit" the instance variable balance and the various methods. Methods can be used as is, if they already do the right thing. If not,
they can be overridden by writing new versions of some of the methods for the new account types.
The Bank Account hierarchy
BankAccount
SavingsAccount
CheckingAccount
The BankAccount Class
public class BankAccount {
private double balance;
public BankAccount() {
balance = e.00;
}
public BankAccount (double initialAmount) {
balance = initialAmount;
public void deposit(double amount) {
balance += amount;
public void withdraw(double amount)
balance -= amount;
public double getBalance() {
return balance;
public void transfer(BankAccount other, double amount) {
withdraw(amount);
other.deposit(amount);
}
Savings Account
Savings account is just like a basic bank account, except that it pays interest. All the methods for the BankAccount class work fine for the SavingsAccount class. The SavingsAccount class has to add
an instance variable interestRate and a method addPeriodiclnterest, but otherwise it is just a BankAccount.
We indicate that SavingsAccount is a subclass of BankAccount by adding the words extends Bankaccount at the end of the header of the class declaration. Because SavingsAccount is a subclass of
BankAccount, SavingsAccount will have copies of all the instance variables and methods of BankAccount. It can then add the declaration for the new instance variable interestRate and the new method
addPeriodiclnterest. Thus, every SavingsAccount object has two instance variables:
balance, which is inherited from BankAccount
interestRate, which is specific to SavingsAccount class.
The SavingsAccount Class
public class SavingsAccount extends BankAccount {
private double interestRate;
public SavingsAccount(double rate) {
interestRate = rate;
public SavingsAccount (double rate, double initialAmount) {
super(initialAmount);
interestRate - rate;
}
þublic void addPeriodicInterest() (
double interest - getBalance() * interestRate / 100.e;
deposit(interest);
Transcribed Image Text:Bank Account Class For our first example, we considered the basic BankAccount Class. Basically, it has an instance variable balance that holds the current balance. We can also provide two constructors: the first creates a new account with a balance of 0.00, the second takes in an initialBalance and uses that for the initial balance. The BankAccount class also has a set of useful methods other than the setter and getter methods: public void deposit(double amount) public void withdraw(double amount) public double inquire() I will no longer discuss the functionalities of these methods. Of course, these methods do what is expected. But I would like to include another method which is defined as follows: public void transfer(BankAccount other, double amount) { balance -- amount, other.balance += amount; (Notice that a method may refer to private instance variables of another object in the same class. This capability has nothing to do with inheritance, but it's good to remember that methods of a class can always access instance variables of any object in the class for which they have a reference, not just the object referenced by this.) This method is used when an account transfers an amount to another account. You noticed from the implementation of that the an amount is deducted from the balance and the same amount is added to the other balance. Other Bank Accounts Banks offer many kinds accounts. A savings account pays periodic interest. A checking account pays no interest and may have transaction fees for deposits and withdrawals. A time deposit account may have an interest penalty for early withdrawal. We could write a separate class for each of these variants of bank accounts. All of these different accounts have a balance, and they all have to deal with deposits, withdrawals, getting the account balance, and transfers. It is this situation that inheritance need to deal with it. The goal is to "inherit" the instance variable balance and the various methods. Methods can be used as is, if they already do the right thing. If not, they can be overridden by writing new versions of some of the methods for the new account types. The Bank Account hierarchy BankAccount SavingsAccount CheckingAccount The BankAccount Class public class BankAccount { private double balance; public BankAccount() { balance = e.00; } public BankAccount (double initialAmount) { balance = initialAmount; public void deposit(double amount) { balance += amount; public void withdraw(double amount) balance -= amount; public double getBalance() { return balance; public void transfer(BankAccount other, double amount) { withdraw(amount); other.deposit(amount); } Savings Account Savings account is just like a basic bank account, except that it pays interest. All the methods for the BankAccount class work fine for the SavingsAccount class. The SavingsAccount class has to add an instance variable interestRate and a method addPeriodiclnterest, but otherwise it is just a BankAccount. We indicate that SavingsAccount is a subclass of BankAccount by adding the words extends Bankaccount at the end of the header of the class declaration. Because SavingsAccount is a subclass of BankAccount, SavingsAccount will have copies of all the instance variables and methods of BankAccount. It can then add the declaration for the new instance variable interestRate and the new method addPeriodiclnterest. Thus, every SavingsAccount object has two instance variables: balance, which is inherited from BankAccount interestRate, which is specific to SavingsAccount class. The SavingsAccount Class public class SavingsAccount extends BankAccount { private double interestRate; public SavingsAccount(double rate) { interestRate = rate; public SavingsAccount (double rate, double initialAmount) { super(initialAmount); interestRate - rate; } þublic void addPeriodicInterest() ( double interest - getBalance() * interestRate / 100.e; deposit(interest);
Checking Account class
The CheckingAccount class again is similar to the besic BankAccount class, but it incorporates transaction fees. In this implementetion, the acccunt owner gets free trensactions per month. After that,
the account cwner must pay a TRANSACTION_FEE fcr eech additional transection (50 cents). These fees are assessed at the end of esch month. In this cese, we declare the constants
FREE TRANSACTIONS and TRANSACTION FEE as static and final since they will never charge (hence fnal) and they should be the same for ell checking acccunts (hence static).
Rather than woryıng strictly abour months, cur implementation ot the CheckingAccount dass JUST womes abour some pennd of unsperitied length Ihe rstance variable transactionCCount counts the
number of ransactions that heve cccurred in the current pencd. To keep this variable up To date, we increment transactionCount every time we make a deposit or a withdrewal The methods deposit
and withdraw that are irherited from the superclass BankAccount do not handle incrementing transactionCount. We must therefore override these methods by writing new versions of them.
We can descr be rhe desired hrhavior of CheckingAcrcunt's withdraw meshod as
Du whet the rnurmal withdraw in BarıkAccount dces, and then inciemerIl LiarisactionCount.
Our implementation of withdraw in CheckingAccount does so. The code super.withdrawamount); says to call the withdraw methcd of the superclass. (If we left off the super. it would try to call
this.withdraw, which is the same method we are writing. We'd get a recursive call of the same method with the seme perameters, which would cause infinite recursion. Big trouble.) Our implementation
of the deposit method is analogous.
The rew merhod deductrees takes care ot transacTIon tees ny compumng the amounT TO be chargerd withdrawing ir trom theaccount, and then serring transactionCount hack 10 1 IT pertoms the
withdrewal by calling super withdraw. (In this case, just calling withdraw woukd also work. It would increase the number of transactions, bur that gens immediarely set back to 0. It is safer to use
withdrew fronm the superclass, which does not desl with transaction fees.)
The CheckingAccount Class
public class CheckingAccount extends BankAccount {
| private static final int FREE_TRANSACTIONS - 3;
private static final double TRANSACTION_FEE = 0.50;
private int transactionCount;
public CheckingAccount () {
transactionCount = 0;
public CheckingAccount(double initialAmount) {
super (initialAmount);
transactionCount = e;
public void withdraw(double amount) {
super.withdraw(amount);
transactionCount++;
public void deposit(double amount) {
super.deposit(amount);
transactionCount++;
public void deductFees () {
if (transactionCount > FREE_TRANSACTIONS) {
double fee = TRANSACTION_FEE (transactionCount - FREE_TRANSACTIONS);
super.withdraw(fee);
transactionCount = e;
Transcribed Image Text:Checking Account class The CheckingAccount class again is similar to the besic BankAccount class, but it incorporates transaction fees. In this implementetion, the acccunt owner gets free trensactions per month. After that, the account cwner must pay a TRANSACTION_FEE fcr eech additional transection (50 cents). These fees are assessed at the end of esch month. In this cese, we declare the constants FREE TRANSACTIONS and TRANSACTION FEE as static and final since they will never charge (hence fnal) and they should be the same for ell checking acccunts (hence static). Rather than woryıng strictly abour months, cur implementation ot the CheckingAccount dass JUST womes abour some pennd of unsperitied length Ihe rstance variable transactionCCount counts the number of ransactions that heve cccurred in the current pencd. To keep this variable up To date, we increment transactionCount every time we make a deposit or a withdrewal The methods deposit and withdraw that are irherited from the superclass BankAccount do not handle incrementing transactionCount. We must therefore override these methods by writing new versions of them. We can descr be rhe desired hrhavior of CheckingAcrcunt's withdraw meshod as Du whet the rnurmal withdraw in BarıkAccount dces, and then inciemerIl LiarisactionCount. Our implementation of withdraw in CheckingAccount does so. The code super.withdrawamount); says to call the withdraw methcd of the superclass. (If we left off the super. it would try to call this.withdraw, which is the same method we are writing. We'd get a recursive call of the same method with the seme perameters, which would cause infinite recursion. Big trouble.) Our implementation of the deposit method is analogous. The rew merhod deductrees takes care ot transacTIon tees ny compumng the amounT TO be chargerd withdrawing ir trom theaccount, and then serring transactionCount hack 10 1 IT pertoms the withdrewal by calling super withdraw. (In this case, just calling withdraw woukd also work. It would increase the number of transactions, bur that gens immediarely set back to 0. It is safer to use withdrew fronm the superclass, which does not desl with transaction fees.) The CheckingAccount Class public class CheckingAccount extends BankAccount { | private static final int FREE_TRANSACTIONS - 3; private static final double TRANSACTION_FEE = 0.50; private int transactionCount; public CheckingAccount () { transactionCount = 0; public CheckingAccount(double initialAmount) { super (initialAmount); transactionCount = e; public void withdraw(double amount) { super.withdraw(amount); transactionCount++; public void deposit(double amount) { super.deposit(amount); transactionCount++; public void deductFees () { if (transactionCount > FREE_TRANSACTIONS) { double fee = TRANSACTION_FEE (transactionCount - FREE_TRANSACTIONS); super.withdraw(fee); transactionCount = e;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY