Question: Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and

Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the current balance to decrease and toString() method returns account name and the current balance separated by a comma. For example if name is Jake and balance is 40.0 it should return

Jake, $40.00

Write a client program called BankAccountClient that creates a BankAccount object called B1 and assigns John to its name field and 1000 to balance field. Call the deposit method to deposit 500 to this account and call the display method to display the current balance. Then, withdraw 300 from this account and print the object using println. Create another object called B2 without passing parameters and display the name and current balance for this object.

I understand the part above. I am a little confused on this part:

Define a counter(integer) variable to BankAccount class to count the number of objects created for the class. Keep the variable private and define a better method for that variable. Create a few objects of BankAccount Class and print the number of objects created for BankAccount in main method.

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!