-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleInput.java
More file actions
74 lines (58 loc) · 2.47 KB
/
SampleInput.java
File metadata and controls
74 lines (58 loc) · 2.47 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package CryptarithmeticSolver;
import java.util.regex.Pattern;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
public final class SampleInput {
@FXML
public TextField wordField;
@FXML
private TextField summationField;
public SampleInput(TreeView<String> optionsTree) {
TreeItem<String> root = new TreeItem<>("Root");
root.setExpanded(true);
TreeItem<String> Easy, Medium, Hard, Addition;
Addition = makeBranch("Addition", root);
Easy = makeBranch("EASY", Addition);
Medium = makeBranch("MEDIUM", Addition);
Hard = makeBranch("HARD", Addition);
makeBranch("A _ B = C", Easy);
makeBranch("AB _ CA = BD", Easy);
makeBranch("AB _ CD = EF", Easy);
makeBranch("SEND + MORE = MONEY", Easy);
makeBranch("DO + YOU + FEEL = LUCKY", Easy);
makeBranch("COUNT - COIN = SNUB", Easy);
makeBranch("BUT + ITS + GOOD = MUSIC", Medium);
makeBranch("HOCUS _ POCUS = PRESTO", Hard);
makeBranch("BATMAN _ NIGHT = GOTHAM", Hard);
makeBranch("SATURN + URANUS = PLANETS", Hard);
makeBranch("GET _ ALONG _ LITTLE = DOGIES", Hard);
makeBranch("THREE + THREE + TWO + TWO + ONE = ELEVEN", Hard);
optionsTree.setRoot(root);
optionsTree.setShowRoot(false);
}
public TreeItem<String> makeBranch(String title, TreeItem<String> parent) {
TreeItem<String> item = new TreeItem<>(title);
item.setExpanded(true);
parent.getChildren().add(item);
return item;
}
public void updateTextfields(TreeItem<String> newValue, TextField wordField, TextField summationField) {
// wordField.setText(newValue.getValue());
wordField.clear();
for (int i = 0; i < newValue.getValue().split(" *").length; i++) {
String sampleInputObject = newValue.getValue().split(" *")[i];
final Pattern pattern = Pattern.compile("^[A-Za-z, ]++$");
if (i == newValue.getValue().split(" *").length - 1) {
if (pattern.matcher(sampleInputObject).matches()) {
summationField.setText(sampleInputObject);
}
} else {
if (pattern.matcher(sampleInputObject).matches()) {
wordField.setText(wordField.getText() + sampleInputObject + ",");
}
}
}
}
}