Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions