So, here's my code. I have a runtime error and I think there's a problem in the loop in it but I can't figure it out.
import java.util.Scanner; public class BankSystem { public static void main(String[] args) { double acc=1000,d,w; int exit, selector; char enter; Scanner keyboard = new Scanner(System.in); System.out.println("To use the bank system, select 'y' or any other letter to exit."); enter = keyboard.nextLine().charAt(0); while (enter == 'y') { System.out.println("Enter one of the following options:"); System.out.println(" * '1' for account balance."); System.out.println(" * '2' for withdraw."); System.out.println(" * '3' for deposit."); selector = keyboard.nextInt(); switch (selector) { case 1: System.out.println("Your balance is: "+acc); break; case 2: System.out.println("Enter the amount to withdraw."); w = keyboard.nextDouble(); if (w<=0 || w>acc) System.out.println("Wrong input."); else acc=acc-w; System.out.println("The selected amount has been withdrawed from your account successfully."); break; case 3: System.out.println("Enter the amount to deposit."); d=keyboard.nextDouble(); while (d<=0) { System.out.println("Wrong input."); System.out.println("Enter the right amount."); d = keyboard.nextDouble(); } acc=acc+d; System.out.println("The selected amount has been deposited into your account successfully."); break; default: System.out.println("Wrong selection."); } System.out.println("To continue using the system, select 'y' or any other letter to exit."); enter = keyboard.nextLine().charAt(0); } System.out.println("System is shutting down..."); } }
Any help or hints on how to correct my error would be great. Thanks.