From 0e6357de71344b79d7693e7c6357c46ee553557c Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Wed, 16 Mar 2016 17:23:43 -0400 Subject: Moved dice parser test to example directories Also made internal pair data holder protected. --- .../utils/examples/DiceExpressionParserTest.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 BJC-Utils2/src/examples/java/bjc/utils/examples/DiceExpressionParserTest.java (limited to 'BJC-Utils2/src/examples/java/bjc') 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(); + } +} -- cgit v1.2.3