My program should ask users to enter some value and evetually those value should be printed out depending on the menu option choosen (in my case it's 3). I have used System.out.println("Your name: " + name);
to print out the name inserted by user, but unfortunately it can't print out the name. The line is just left empty. Why so? How can I fix it.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int userChoose;
String name = null;
int accNum = 0;
double initiateAmount = 0;
double newAmm = 0;
double depOrWith = 0;
System.out.println("WELCOME TO OUR BANK!\n\n"
+ "...................\n"
+ "...................\n\n"
+ "Choose your optiin:\n"
+ "1. Create new account\n"
+ "2. Deposit/withdraw\n"
+ "3. View details\n"
+ "4. Deleting an account\n"//not used yet
+ "5. View all the accounts\n"//not used yet
+ "6. Quit\n\n");
System.out.println("*************\n"
+ "************");
while (true) {
userChoose = sc.nextInt();
if (userChoose == 1) {
System.out.println("Enter your full name:");
name = sc.nextLine();
sc.nextLine();
System.out.println("Choose an account number:");
accNum = sc.nextInt();
System.out.println("Enter an initiating amount:");
initiateAmount = sc.nextDouble();
System.out.println("\n-----------\n"
+ "------------");
} else if (userChoose == 2) {
System.out.println("Enter negative value to withdraw and positive to deposit");
depOrWith = sc.nextInt();
if (depOrWith < 0) {
initiateAmount = initiateAmount + depOrWith;
} else {
initiateAmount = initiateAmount + depOrWith;
}
System.out.println("\n-----------\n"
+ "------------");
} else if (userChoose == 3) {
System.out.println("Your name: " + name);
System.out.println("Your account number: " + accNum);
System.out.println("Your current balance: " + initiateAmount);
System.out.println("\n-----------\n"
+ "------------");
} else if (userChoose == 6) {
System.exit(0);
}
}
}