-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentenceGen.java
More file actions
35 lines (31 loc) · 983 Bytes
/
sentenceGen.java
File metadata and controls
35 lines (31 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.*;
import java.util.*;
class sentenceGen {
String noun;
String adjective;
public sentenceGen (){
noun = "nouns.txt";
adjective = "adjectives.txt";
}
public String getRandomWord(String wordType){
ArrayList<String> wordStorage = new ArrayList<>();
try{
File fileReader = new File(wordType);
Scanner s = new Scanner(fileReader);
for(int y = 0; s.hasNextLine(); y++){
String word = s.nextLine();
wordStorage.add(word);
}
}
}
catch(Exception e){
System.out.println("File not found ! ");
}
Random r = new Random();
int randomNumber = r.nextInt(wordStorage.size());
return wordStorage.get(randomNumber);
}
public void getSentence(){
System.out.println(getRandomWord(noun) + " is so " + getRandomWord(adjective));
}
}