I have a problem with my code. When I get prompted if i want to deposit, withdraw, or view my balance I type balance and it shows me the balance but they shows code that I also have in place and says "Unknown command", how do I stop this? Thank you. Here is the code:
import java.util.Scanner; import java.util.Random; public class bankSystem { public static void main(String[] args) { Scanner kb = new Scanner(System.in); double balance = 100; int password; double bankBalance; double interest = .01; int withdrawDeposit; String withdrawDepositAnswer = null; int withdrawAmount; int depositAmount = 0; Random rng = new Random(); int randomInt = rng.nextInt(100); String name; System.out.println("Enter name to recieve password!"); name = kb.next(); System.out.println("Your randomly generated password is : " + randomInt); for (int idx = 1; idx <= 10; ++idx) { } password = randomInt; while(true){ System.out .println("Hello, welcome to the bank! Please enter password to access account."); password = kb.nextInt(); if (password == randomInt) { System.out .println("Welcome to your account! Would you like to withdraw, deposit, or view your balance?"); withdrawDepositAnswer = kb.next(); if (withdrawDepositAnswer.equalsIgnoreCase("balance")) { System.out.println("$" + balance); } if (withdrawDepositAnswer.equalsIgnoreCase("Withdraw")) { System.out.println("How much would you like to withdraw?"); withdrawAmount = kb.nextInt(); if (withdrawAmount > balance) { System.out .println("Sorry you don't have enough money left for that!"); return; } else if (balance > withdrawAmount) { balance = balance - withdrawAmount; } System.out.println("Your remaining balance is $ " + balance); } else if (withdrawDepositAnswer.equalsIgnoreCase("Deposit")) { System.out.println("How much would you like to deposit?"); depositAmount = kb.nextInt(); balance = balance + depositAmount; System.out.println("Your new balance is $ " + balance); } else { System.out.println("Unknown command."); } } else { System.out.println("Access Denied."); } } } }