Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Bank System Simulator

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Bank System Simulator

    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.");
    		}
     
     
     
     
     
    		}
     
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Bank System Simulator

    Please copy the full contents of the command prompt window that shows what you are describing and paste it here.

    On windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.


    Hint: Add the value that is "unknown" to the error message so you can see what the computer sees when it executes the code.

    --- Update ---

    We crossed while I added to my post:

    Hint: Add the value that is "unknown" to the error message so you can see what the computer sees when it executes the code.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Bank System Simulator

    Please copy and paste the text, no images. Text can't be copied from images for responses and text is easier to read.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Bank System Simulator

    Welcome to your account! Would you like to withdraw, deposit, or view your balance?
    balance
    $100.0
    Unknown command.
    Hello, welcome to the bank! Please enter password to access account.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Bank System Simulator

    Strange when I run the code I get this question first:
    Enter name to recieve password!
    Your randomly generated password is : 35
    Why doesn't the command prompt window's contents you posted show that?


    Also you are ignoring this:

    Hint: Add the value that is "unknown" to the error message so you can see what the computer sees when it executes the code.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. water simulator
    By watersimulator in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 1st, 2013, 10:36 PM
  2. Traffic Simulator
    By slimergan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 5th, 2012, 06:38 AM
  3. smpp simulator
    By ridg18 in forum Java Theory & Questions
    Replies: 3
    Last Post: September 21st, 2012, 06:57 PM
  4. Developing a simulator
    By jack_nutt in forum AWT / Java Swing
    Replies: 1
    Last Post: September 5th, 2012, 07:06 AM
  5. JAVA simulator
    By YAS218 in forum Java Theory & Questions
    Replies: 8
    Last Post: July 20th, 2009, 09:57 AM