summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/examples/java/bjc
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/examples/java/bjc')
-rw-r--r--BJC-Utils2/src/examples/java/bjc/utils/examples/DiceExpressionParserTest.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/DiceExpressionParserTest.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/DiceExpressionParserTest.java
new file mode 100644
index 0000000..002501b
--- /dev/null
+++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/DiceExpressionParserTest.java
@@ -0,0 +1,62 @@
+package bjc.utils.examples;
+
+import java.util.Scanner;
+
+import bjc.utils.dice.DiceExpressionParser;
+import bjc.utils.dice.IDiceExpression;
+
+/**
+ * Driver class for testing expression parser
+ *
+ * @author ben
+ *
+ */
+public class DiceExpressionParserTest {
+ /**
+ * Run the parser test
+ *
+ * @param args
+ * Unused CLI arguments
+ */
+ public static void main(String[] args) {
+ /*
+ * Get a scanner for input
+ */
+ Scanner scn = new Scanner(System.in);
+
+ /*
+ * Ask to enter a expression
+ */
+ System.out.print("Enter dice expression: ");
+
+ String exp = scn.nextLine();
+
+ /*
+ * Enter amount of times to roll an expression
+ */
+ System.out.print("Enter number of times to roll: ");
+
+ int nTimes = Integer.parseInt(scn.nextLine());
+
+ /*
+ * Parse the string expression into a dice expression
+ */
+ DiceExpressionParser dep = new DiceExpressionParser();
+
+ IDiceExpression dexp = dep.parse(exp);
+
+ /*
+ * Roll the dice a specified amount of times
+ */
+ for (int i = 1; i <= nTimes; i++) {
+ int roll = dexp.roll();
+
+ System.out.println("Rolled " + roll);
+ }
+
+ /*
+ * Clean up after ourselves
+ */
+ scn.close();
+ }
+}