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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!