Results 1 to 3 of 3

Thread: error in code

  1. #1
    dirtycash is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default error in code


    The deposit command allows a user to deposit money into an existing account.
    The cashier must ask for the email address of the account, the password and the
    amount to be deposited. If the password is correct, the money will be deposited into
    the account. If the deposit could not be completed, the cashier prints out a message
    informing the user. If the deposit is completed successfully, the cashier responds
    with “Thank you for using the bank”.
    Java Code:
    
        private void makeDeposit(InputReader reader)
        {
            String email = reader.getText("enter email address: ");
            String password = reader.getText("enter password: ");
            int amount = reader.getNumber("enter deposit amount: ");
            if(accounts.containsKey(email))
            {
                Account account = (Account)accounts.get(email);
                if(account.getPassword().equals(password))
                {
                    boolean success = account.deposit(amount);
                    if(success)
                        System.out.println("Thank you for using the bank");
                    else
                        System.out.println("Unable to deposit to your account");
                }
            }
        }
    it doesn't come up with the print messages whilst testing it
    can anyone see where its gone wrong?

    thanks.

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    If neither the 'thank you' nor 'unable to deposit' String are printing then it has to be something with the other two ifs. Double check that you are entering valid email and password data.

  3. #3
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    It always help to print out the data when debugging (or using a debugger) to see what the computer is doing with the data. You might think you are typing in the right email, but it might not be contained in the accounts.

Similar Threads

  1. Help with code (static error)
    By oceansdepth in forum New To Java
    Replies: 1
    Last Post: 03-28-2008, 05:32 AM
  2. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 11:12 PM
  3. Pls help with a code error.
    By saytri in forum New To Java
    Replies: 8
    Last Post: 12-24-2007, 09:10 PM
  4. error stack when I try to execute my code
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 09:32 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •