Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. private Scanner file;
  2. private final List<String> words;
  3.  
  4. public TextFile(){
  5. words = readFile();
  6. }
  7.  
  8. public String getWord(){
  9.  
  10. return numOfWords;
  11.  
  12. }
  13.  
  14. private List<String> readFile() {
  15.  
  16. List<String> wordList = new ArrayList<String>();
  17.  
  18. try {
  19. file = new Scanner(new File("words.txt"));
  20.  
  21. }
  22.  
  23. } catch (FileNotFoundException e) {
  24. System.out.println("File Not Found");
  25. } catch (Exception e) {
  26. System.out.println("IOEXCEPTION");
  27. }
  28.  
  29. return wordList;
  30. }
  31.  
  32. public static void main(String[] args) {
  33.  
  34. TextFile file = new TextFile();
  35. }
  36.  
  37. List<String> words; // assign stuff to words
  38. Random r = new Random();
  39.  
  40. //yields random number in the range of 0 to words.size()-1 inclusive
  41. int num = r.nextInt(words.size());
  42.  
  43. List<String> words; // assign stuff to words
  44. int index = (int)(Math.random() * words.size());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement