Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

inputreader5

By: ace on Feb 10th, 2010  |  syntax: None  |  size: 1.46 KB  |  hits: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.util.HashSet;
  2. import java.util.Scanner;
  3. import java.util.ArrayList;
  4.  
  5. /**
  6.  * InputReader reads typed text input from the standard text terminal.
  7.  * The text typed by a user is then chopped into words, and a set of words
  8.  * is provided.
  9.  *
  10.  * @author     Michael Kolling and David J. Barnes
  11.  * @version    1.0
  12.  */
  13. public class InputReader
  14. {
  15.     private Scanner reader;
  16.     private String trueInput;
  17.  
  18.     /**
  19.      * Create a new InputReader that reads text from the text terminal.
  20.      */
  21.     public InputReader()
  22.     {
  23.         reader = new Scanner(System.in);
  24.         trueInput = reader.nextLine();
  25.     }
  26.  
  27.     /**
  28.      * Read a line of text from standard input (the text terminal),
  29.      * and return it as a set of words.
  30.      *
  31.      * @return  A set of Strings, where each String is one of the
  32.      *          words typed by the user
  33.      */
  34.     public ArrayList<String> getInput()
  35.     {
  36.         System.out.print("> ");                // print prompt
  37.         String inputLine = reader.nextLine().trim().toLowerCase();
  38.         String trueInput =inputLine;
  39.         String[] wordArray = inputLine.split(" ");  // split at spaces
  40.  
  41.         // add words from array into hashset
  42.         ArrayList<String> words = new ArrayList<String>();
  43.         for(String word : wordArray) {
  44.             words.add(word);
  45.         }
  46.         return words;
  47.     }
  48.    
  49.     public String getTrueInput()
  50.     {
  51.         return trueInput;
  52.     }
  53.    
  54.    
  55. }