Skip to content

Instantly share code, notes, and snippets.

@tomorrowkey
Last active December 14, 2015 18:08
Show Gist options
  • Save tomorrowkey/5126812 to your computer and use it in GitHub Desktop.
Save tomorrowkey/5126812 to your computer and use it in GitHub Desktop.
Update, the answer will trim.
package jp.tomorrowkey.englishpractice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Main {
private static ArrayList<Item> itemArray;
static {
itemArray = new ArrayList<Main.Item>();
itemArray.add(new Item("give", "to"));
itemArray.add(new Item("hand", "to"));
itemArray.add(new Item("lend", "to"));
itemArray.add(new Item("send", "to"));
itemArray.add(new Item("sell", "to"));
itemArray.add(new Item("show", "to"));
itemArray.add(new Item("write", "to"));
itemArray.add(new Item("bring", "to"));
itemArray.add(new Item("teach", "to"));
itemArray.add(new Item("throw", "to"));
itemArray.add(new Item("mail", "to"));
itemArray.add(new Item("read", "to"));
itemArray.add(new Item("tell", "to"));
itemArray.add(new Item("owe", "to"));
itemArray.add(new Item("pass", "to"));
itemArray.add(new Item("buy", "for"));
itemArray.add(new Item("build", "for"));
itemArray.add(new Item("find", "for"));
itemArray.add(new Item("make", "for"));
itemArray.add(new Item("bake", "for"));
itemArray.add(new Item("cook", "for"));
itemArray.add(new Item("get", "for"));
itemArray.add(new Item("do [a favour]", "for"));
}
public static void main(String... args) throws Exception {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
int index = (int)Math.floor(Math.random() * itemArray.size());
Item item = itemArray.get(index);
System.out.println(item.getVerb() + " ?");
String answer = reader.readLine();
if (item.getPreposition().equalsIgnoreCase(answer.trim())) {
System.out.println("Correct!");
} else {
System.err.println("Incorrect...");
}
System.out.println();
}
} finally {
if (reader != null)
reader.close();
}
}
static class Item {
private String verb;
private String preposition;
public Item(String verb, String preposition) {
this.verb = verb;
this.preposition = preposition;
}
public String getVerb() {
return verb;
}
public void setVerb(String verb) {
this.verb = verb;
}
public String getPreposition() {
return preposition;
}
public void setPreposition(String preposition) {
this.preposition = preposition;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment