Results 1 to 2 of 2

Thread: command help

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

    Default command help

    ............................
    Last edited by dirtycash; 12-09-2007 at 10:10 PM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class CashierTest
    {
        public static void main(String[] args)
        {
            InputReader reader = new InputReader();
            Cashier cashier = new Cashier();
            cashier.generateResponse(Cashier.CREATE, reader);
            cashier.generateResponse(Cashier.DEPOSIT, reader);
        }
    }
    
    class Cashier
    {
        HashMap<String, Account> accounts;
        final static String CREATE  = "create";
        final static String DEPOSIT = "deposit";
        
        public Cashier()
        {
            accounts = new HashMap<String, Account>();
        }
    
        public void generateResponse(String word, InputReader reader)
        {
            if(word.equals(CREATE))
            {
                createAccount(reader);
            }
            if(word.equals(DEPOSIT))
            {
                makeDeposit(reader);
            }
        }
    
        private void createAccount(InputReader reader)
        {
            String email = reader.getText("enter email address: ");
            String password = reader.getText("enter password: ");
            if(accounts.containsKey(email))
            {
                System.out.println("The account already exists");
            }
            else
            {
                Account account = new Account(email, password);
                accounts.put(email, account);
                System.out.println("Your account has been created");
            }
        }
    
        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");
                }
            }
        }
    }

Similar Threads

  1. command
    By dirtycash in forum New To Java
    Replies: 8
    Last Post: 01-02-2008, 07:52 PM
  2. Exporting from the command line
    By o1121 in forum Eclipse
    Replies: 1
    Last Post: 08-09-2007, 07:29 PM
  3. Eclipse underliying command
    By o1121 in forum Eclipse
    Replies: 2
    Last Post: 08-08-2007, 07:27 AM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM
  5. problems with jar command
    By simon in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 04:21 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
  •