public void deposit(double depositAmount, String userName) throws IOException {
//opens the file that stores the account balance
File balanceLocation = new File(ACCOUNT_BALANCE_LOCATION+userName+".txt");
//creates an object of the scanner class
Scanner balanceReader = new Scanner(ACCOUNT_BALANCE_LOCATION+balanceLocation+".txt");
//creates print writer object
PrintWriter deposit = new PrintWriter (balanceLocation);
double balance = balanceReader.nextDouble();
double postDepositBalance = balance + depositAmount;
deposit.println(postDepositBalance);
deposit.close();
balanceReader.close();
}
Below code is in main I expected the program to work but every time I attempt to deposit any amount to the file it gives me an error:
String depositAmount = JOptionPane.showInputDialog("Enter Deposit Amount:");
double convertedDeposit = Double.parseDouble(depositAmount);
JOptionPane.showMessageDialog(null, "New Balance: $"+ convertedDeposit);
bank.deposit(convertedDeposit, username);
JOptionPane.showMessageDialog(null, "New Balance: $"+ bank.balance(username));
I expected it to input the deposited amount to the file but instead got java.util.InputMismatchException