I have an ArrayList of accounts containing the attributes accountNumber, accountHolder, and balance. Previously, my method would take the name of the object as an argument. For the purpose of preventing user error, I would like my program to create a new object upon calling a method and automatically name that object based on how many objects are already existing in my ArrayList. The issue I am running into (I think) is the fact that I can not convert a string into an object.
public void addAccount(String newAccountNumber, String newAccountHolder, double newStartingBalance)
{
String newAccountName = "account" + accounts.size() + 1;
accounts.add(newAccountName);
int x = accounts.indexOf(newAccountName);
accounts.get(x).setAccountNumber(newAccountNumber);
accounts.get(x).setAccountHolder(newAccountHolder);
accounts.get(x).setBalance(newStartingBalance);
}