Question: Next build and Test an AccountList class. Properties: An array(or ArrayList) of Accounts and a Count. Constructors: only a default constructor is needed. Behaviors: addAccount(Account
Next build and Test an AccountList class. Properties: An array(or ArrayList) of Accounts and a Count. Constructors: only a default constructor is needed. Behaviors: addAccount(Account a) and display(). To test the AccountList class, in main(), instantiate an AccountList object and add maybe 2 Accounts to the AccountList, and then display() the AccountList.
Lastly, add an AccountList property to the Customer class. A Customer has a List of Accounts. The Customers display() function will also need to be modified to display() the Customers AccountList.
I need help with the last part please. How do I change it so that the Account List is not passed to the constructor?
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Customer2 extends Person2{ //Properties public int password; public int customerID; public AccountList2 list; //Constructors public Customer2(){ super(); list = new AccountList2(); password = 0; customerID = 0; } public Customer2(int pw, int cid ,String fn, String ln, String addr, String em, AccountList2 li){ super(fn, ln, addr, em); password = pw; list = li; customerID = cid; } //Behaviors public void setPw(int pw){ password = pw; } public int getPw(){ return password; } public void setList(AccountList2 li){ list = li; } public AccountList2 getList(){ return list; } public void setCid(int cid){ customerID = cid; } public int getCid(){ return customerID; } public void display(){ System.out.println(""); System.out.println("Password: " + getPw()); System.out.println("Customer ID: " + getCid()); super.display(); list.display(); } public static void main(String[] args){ Customer2 c2; c2 = new Customer2(); c2.display(); Customer2 c3; c3 = new Customer2(9999,3006,"Bill","Gates","Washington","bgates@msn.com", new AccountList2()); c3.display(); } }
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class AccountList2{ //Properties public int count = 0; public Account2 aList[] = new Account2[4]; //Constructors public AccountList2(){ } //Behaviors public void addAccount2(Account2 a2){ aList[count] = a2; count++; } public void display(){ System.out.println("Account List Display"); for(int x = 0; x < count; x++){ aList[x].display(); } } public static void main(String[] args){ AccountList2 myList = new AccountList2(); myList.addAccount2(new Account2(90000,3003,"SAV",8855.90)); myList.addAccount2(new Account2(90001,3003,"CHK",786.54)); myList.display(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
