I try to print the list of accounts but they appear as @164552...
I tried to call the toString method like Arrays.toString(accounts) but it doesnt compile.
It complains about static and the that it can not resolve method toString
import java.util.ArrayList;
import java.util.Arrays;
public class Customer {
private String name;
private String surname;
private String personalNumber;
private ArrayList<Account> accounts;
public Customer(String customerName, String customerSurname,
String customerPersonalNumber) {
this.name = customerName;
this.surname = customerSurname;
this.personalNumber = customerPersonalNumber;
this.accounts = new ArrayList<Account>();
}
public Customer() {
}
public String getCustomerInfo() {
return name + " " + surname + " " + personalNumber + accounts;
}
public ArrayList<Account> getAllAccounts() {
return accounts;
}
public static void main(String[] arg) {
Customer p = new Customer("Anna", "Larsson", "112323");
p.addAccounts(new SavingsAccount());
p.addAccounts(new SavingsAccount());
System.out.println(Arrays.toString(accounts));
}
}
arg). 2.Arrays.toStringtakes an array, not anArrayList. 3. If you overrideObject.toStringinAccount, you would be able to see meaningful information by just printing usingSystem.out.println(accounts);