I am creating a bankteller loop java code. I am trying to ask the user for what amount of money they would like to deposit into their account. I can get this to work once. For example, they will enter in $20 the first time. Then they will decide to put in $10 more. However, instead of displaying the current balance at $30, it only displays the one recently entered (the $10). How do I fix this?
Here is my code for that part of the loop in the menu that calls the class:
else if( userInput == 3 ){
Account account = new Account();
System.out.print("\nHow much would you like to deposit?: ");
float money = input.nextFloat();
account.deposit(money);
}
Here is the code for deposit that is called:
public void deposit(float money) {
if (money < 0) {
System.err.println("Error: Can't deposit negative money.\n");
return;
}
else {
currentBalance = money + currentBalance;
System.out.println("Current balance: $" + currentBalance + "\n");
}
}