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 dice; private int numDice; private int numSides; public Dice(int numDice_, int numSides_) { this.dice = new ArrayList<>(); this.numDice = numDice_; this.numSides = numSides_; } public Dice(int numDice_) { this.dice = new ArrayList<>(); this.numDice = numDice_; this.numSides = 6; } public Dice() { this.dice = new ArrayList<>(); this.numDice = 5; this.numSides = 6; } public int count() { return numDice; } public int getNumSides() { return numSides; } public void addDie(Die die) { dice.add(die); } public void rollDice() { for(int i = 0; i < dice.size(); ++i) { dice.get(i).roll(); } } public void printDice() { System.out.println("Value of each die rolled."); for(int i = 0; i < dice.size(); ++i) { System.out.print(dice.get(i).getCurrentValue() + " "); } System.out.println(" "); } }

************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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!