Question
. Write a class called BankAccount. This class has one instance variable called balance,which is of the data type integer. In addition, there are three
. Write a class called BankAccount. This class has one instance variable called balance,which is of the data type integer. In addition, there are three methods, whose requirements are given below.
Method called getBalance, which is a getter for the instance variable balance.
Method called deposit that has a void return type and takes in a parameter called amount, of the type double. This method calculates a new variable called newBalance = balance + amount, where balance is the current value of instance variable. Once the newBalance is calculated, set the value of instance variable balance = newBalance. Make sure newBalance is declared within the method.
Method called withdraw that has a void return and takes in a parameter called amount, of the type double. This method calculates a new variable called newBalance = balance - amount, where balance, is the current value of instance variable. Once the newBalance is calculated, set the value of instance variable balance = newBalance. Make sure newBalance is declared within the method.
Please note: while you can avoid using variable newBalance in the methods, please write your methods as per the given instruction for this problem.
Copy and paste the code of the class BankAccount here:
Step 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