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
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