Question: Using the Die.java, Dice.java and DiceTester.java code shown below create these two methods in the Dice object and test them using the DiceTester object. int
Using the Die.java, Dice.java and DiceTester.java code shown below create these two methods in the Dice object and test them using the DiceTester object.
int smallStraightValue() If four of the five dice are in a consecutive order, return 30. Otherwise, return 0. (1-2-3-4, 2-3-4-5, or 3-4-5-6) int largeStraightValue() If all five dice are in a consecutive order, return 40. Otherwise, return 0. (1-2-3-4-5 or 2-3-4-5-6)
*************Die.java***************
import java.util.*; public class Die { private String name; private int numSides; private int currentValue; private Random generator = new Random(); public Die() { this.numSides = 0; this.currentValue = 0; } public Die (int numSides_) { numSides = numSides_; currentValue = 0; } public int getNumSides() { return numSides; } public int getCurrentValue() { return currentValue; } public int roll() { this.currentValue = generator.nextInt(numSides) + 1; return currentValue; } public String toString() { String result=""; result += Integer.toString(currentValue); return result; } }
*************Dice.java****************
import java.util.*; public class Dice { private ArrayList
************DiceTester.java*****************
public class DiceTester { public static void main(String[] args) { Dice dice = new Dice(5,6); for(int i = 0; i < dice.count(); i++) { dice.addDie(new Die(dice.getNumSides())); } dice.rollDice(); dice.printDice(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
