Results 1 to 9 of 9

Thread: command

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

    Default command

    ...............
    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
    8

    Default

    Java Code:
    import java.util.*;
    
    public class CashierTest
    {
        public static void main(String[] args)
        {
            InputReader reader = new InputReader();
            Cashier cashier = new Cashier();
            cashier.generateResponse(Cashier.CREATE, reader);
        }
    }
    
    class Cashier
    {
        HashMap<String, Account> accounts;
        final static String CREATE = "create";
        
        public Cashier()
        {
            accounts = new HashMap<String, Account>();
        }
    
        public void generateResponse(String word, InputReader reader)
        {
            if(word.equals(CREATE))
            {
                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");
                }
            }
        }
    }
    
    
    class InputReader
    {
        Scanner scanner = new Scanner(System.in);
    
        public String getText(String prompt)
        {
            System.out.println(prompt);
            return scanner.nextLine();
        }
    
        public int getNumber(String prompt)
        {
            System.out.println(prompt);
            return scanner.nextInt();
        }
    }

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

    Default

    why is this needed?

    class InputReader
    {
    Scanner scanner = new Scanner(System.in);

    public String getText(String prompt)
    {
    System.out.println(prompt);
    return scanner.nextLine();
    }

    public int getNumber(String prompt)
    {
    System.out.println(prompt);
    return scanner.nextInt();
    }

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

    Default

    why is this needed?
    Because an object of type InputReader is specified in the method signature of this method:
    Java Code:
    public void generateResponse(String word, InputReader reader)
    So we need an InutReader class to pass as an argument to the method.

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

    Default

    Java Code:
    import java.io.InputStream;
    import java.util.Scanner;
    import java.util.*;
    
    /**
     * 
     */
    public class InputReader
    {
        private Scanner reader;
         Scanner in=new Scanner(System.in); 
       
        //scanner object to get input from keyboard later
    
        /**
         * Create a new InputReader that reads text from the text terminal.
         */
        public InputReader()
        {
            reader = new Scanner(System.in);
        }
        
        /**
         * Create a new InputReader that reads text from an input stream.
         * @param in An input stream to read from.
         */
        public InputReader(InputStream in) {
            reader = new Scanner(in);
        }
    does any of this code do that already by any chance?

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

    Default

    It looks like it's headed in that direction, yes.

  7. #7
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Topic?

    Excuse me, but what is the topic for this thread?:confused:
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  8. #8
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Quote Originally Posted by tim View Post
    Excuse me, but what is the topic for this thread?:confused:
    command
    ...............

    lol
    dont worry newbie, we got you covered.

  9. #9
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    Quote Originally Posted by roots View Post
    command
    ...............

    lol
    I hope you guys are having fun! ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Similar Threads

  1. command help
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 12:24 AM
  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
  •