Refferencing a string to an existing object
I'm currently learning Java from some books for an OU course that my dad did. One of the situations used to help with the learning is a bank accounts setting. As I want to create an Android app around as similar idea, I was changing some of the source code for the "Accounts" class to make it more user friendly for my own use in the future.
I have a method called transfer, allowing the user to transfer money from one account to another. Previously this method had two arguments, amount and account, however I have changed the method to the following:
The problem I have is that after the user has input the account they wish to transfer to via the dialog box, this is stored as a string. This means that at the line "account.credit(amount);" the method credit is searched for in the class string, rather than in the account class and run on the object with the same name as the string. Is there a way I can reference the string account that the user has entered to an existing object of the class account, so the method credit will then run on this?
public void transfer()
int amount = Integer.parseInt(OUDialog.request("How much do you want to transfer"));
String account = OUDialog.request("Which account do you want to transfer the money to?");
if (amount <= this.getBalance())
this.setBalance(this.getBalance() - amount);
OUDialog.alert("Your new balance is " + this.getBalance);
OUDialog.alert("You do not have sufficient funds for this transaction");