Results 1 to 9 of 9
Thread: command
- 12-03-2007, 11:38 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
- 12-04-2007, 12:25 AM #2Java 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(); } }
- 12-04-2007, 12:37 AM #3
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
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();
}
- 12-04-2007, 01:27 AM #4
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)
- 12-04-2007, 01:30 AM #5
Member
- Join Date
- Nov 2007
- Posts
- 38
- Rep Power
- 0
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); }
- 12-04-2007, 01:46 AM #6
It looks like it's headed in that direction, yes.
- 01-02-2008, 08:48 PM #7
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.
- 01-02-2008, 08:50 PM #8
- 01-02-2008, 08:52 PM #9
Similar Threads
-
command help
By dirtycash in forum New To JavaReplies: 1Last Post: 12-05-2007, 01:24 AM -
Exporting from the command line
By o1121 in forum EclipseReplies: 1Last Post: 08-09-2007, 08:29 PM -
Eclipse underliying command
By o1121 in forum EclipseReplies: 2Last Post: 08-08-2007, 08:27 AM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 01:23 AM -
problems with jar command
By simon in forum Advanced JavaReplies: 1Last Post: 07-13-2007, 05:21 PM
Bookmarks