forked from ColtonPhillips/vtn-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateTheme.java
47 lines (38 loc) · 1.35 KB
/
GenerateTheme.java
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
36
37
38
39
40
41
42
43
44
45
46
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
public class GenerateTheme {
public static ArrayList<String> getArrayListFromFile(File f)
throws FileNotFoundException {
Scanner s;
ArrayList<String> list = new ArrayList<String>();
s = new Scanner(f);
while (s.hasNext()) {
list.add(s.next());
}
s.close();
return list;
}
public static <T> T choose(List<T> list) {
Random randomGenerator = new Random();
int index = randomGenerator.nextInt(list.size());
return list.get(index);
}
public static String title(String s) {
return s.substring(0, 1).toUpperCase() + s.substring(1);
}
public static void main (String[] args) {
try {
ArrayList<String> verbs = getArrayListFromFile(new File("verbs.txt"));
ArrayList<String> nouns = getArrayListFromFile(new File("nouns.txt"));
for (int i = 0; i < 100; i++) {
System.out.println(title(choose(verbs)) + " the " + title(choose(nouns)));
}
} catch (FileNotFoundException e) {
System.err.println("File not found exception: " + e.getMessage());
}
}
}