Question: Java Program Create a new main class called AccountDemo. a) In the main method of this class create three BankAccount objects and deposit three different
Java Program
Create a new main class called AccountDemo.
a) In the main method of this class create three BankAccount objects and deposit three different amounts of money into these three bank accounts.
b) Using the generics mechanism, create a List object that can hold BankAccount objects, call it accountList. Then add the three BankAccount object created in part (a) to this list (remember you will need to import from java.util to use the List class)
c) Try printing the accountList object to the screen; you will see that the BankAccount objects are not displayed correctly as they have no meaningful toString method defined.
d) Add a suitable toString method to the BankAccount class in your project folder.
e) Go back to your AccountDemo program and try printing the accountList object to the screen again; you should see more meaningful output now you have a meaningful toString method defined in the BankAccount class.
f) Instead of printing the accountList object, write an enhanced for loop that prints each bankAccount item in turn on a new line (again making use of the toString method).
Thank you.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
