Question
This is Java and please make simple program and put // (comment) when as needed, Thank you. In this problem, you are going to enhance
This is Java and please make simple program and put // (comment) when as needed, Thank you.
In this problem, you are going to enhance the BankAccount class of Chapter 3, page 94 and 95. You should already have this coded. We are going to enhance it by making the deposit and withdraw methods more realistic. You could not withdraw any amount of money if your balance was less than or equal to 0. You also could not deposit a negative amount.
a. Create a new class named EnhancedBankAccount.
b. If you have it copy BankAccount to EnhancedBankAcount. If you no longer have the BankAccount class, copy the BankAccount class form page 94 and 95.
c. In the deposit method, check to see if the deposit is negative. If it is, then print You cannot make a negative deposit and do not make the deposit. If it is not, make the deposit.
d. In the withdraw method, check to see if the balance the amount to withdraw is less than 0. If it is then print You do not have enough money to make the withdrawal. If it is not, make the withdrawal.
e. Create a EnhancedBankAccountTester by either copying the prior one or entering the code from the text on page 101. Make sure the reference to BankAccount is changed to EnhancedBankAccount.
f. Enter the code as it appears on page 101.
g. Make a negative deposit.
h. Print the balance of harryChecking account.
i. Make a withdrawal greater than the balance.
j. Print the balance of harryChecking account.
94 Chapter 3 Implementing Classes Table 1 Implementing Classes Example publtc class BankAccountt...1 prtvata doubla balance; publtc double gatBalanceo. . . 1 This is the start of a class declaration. Instance variables, methods, and constructors are placed inside the braces. This is an instance variable of type double. Instance variables should be declared as private This is a method declaration. The body of the method must be placed inside the braces. This is the body of the getBa1ance method The raturn t return bal statement returns a value to the caller of the method publtc votd dapastt(double amount) t..1 This is a method with a parameter variable (amount). Because the method is declared as void, it has no return value This is the body of the depostt method. It does not have a return statement This is a constructor declaration. A constructor has the same name as the class and no return type. This is the body of the constructor. A constructor should talance -balance+amount; talance-0; initialize the instance variables. There is one method left, gatBalanco. Unlike the deposit and withdraw methods, which modify the instance variable of the object on which they are invoked, the gatBalanca method returns a value public double gatBalanca) return balanco; We have now completed the implementation of the BankAccount class-see the code listing below. There is only That is the topic of the next section. one step remaining: testing that the class works correctly. sectlon 3/BankAccount Java 2 Abank account has a balance that can be changed by 3 deposits and withdrawals. 5 public class BankAccount 7 private double balance; 9 10 Constructs a bank account wwith a zero balance 12 public BankAccountO 13 alanca - 0; 15Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started