Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a simple die rolling game in java Use the code for Die.java, Dice.java and ScoreCard.java below to complete the assignment Create a file named

Create a simple die rolling game in java Use the code for Die.java, Dice.java and ScoreCard.java below to complete the assignment Create a file named SoloGame.java to use the methods of ScoreCard in a solo dice game. Create a menu-driven text interface to test the calls interactively to simulate a solo game, similar to the test-run, allowing users to select any of the five dice for rerolling, up to three total rolls. 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;} 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; int onesValue; int twosValue; public Dice(){ this.dice = new ArrayList(); this.numDice = 5; this.numSides = 6; for(int i = 0; i

ScoreCard.java public class ScoreCard { private int onesScore = 0; private int twosScore = 0; private int threesScore = 0; private int totalScore = 0; Dice dice = new Dice(); public void rollDice(boolean list[]){ for(boolean value : list){ if(value){ scoreOnes(); scoreTwos(); scoreThrees();}}} public void scoreOnes(){ this.onesScore=(dice.onesValue());} public void scoreTwos(){ this.twosScore=(dice.twosValue());} public int getOnesScore(){ return onesScore;} public int getTwosScore(){ return twosScore;} public void scoreThrees(){ this.threesScore=(dice.threesValue());} public int getThreesScore(){ return threesScore;} public int getTotalScore(){ return onesScore+twosScore+threesScore;} public void displayScoresheet(){ System.out.print("Dice Throw #1: "); dice.printDice(); System.out.println(); System.out.println("Current Scoresheet"); System.out.println("1. Ones : "+(String.format("%2s ", +getOnesScore()))); System.out.println("2. Twos : "+(String.format("%2s ", +getTwosScore()))); System.out.println("3. Threes : "+(String.format("%2s ", +getThreesScore()))); System.out.println("Total : "+(String.format("%2s ", +getTotalScore())));}}

Example output where numbers in bold are user entered values.

image text in transcribed

Turn #1 of 3 Turn #2 of 3 Turn #2 of 3 Final Scoresheet: Current Scoresheet: Current Scoresheet: Current Scoresheet: 1. Ones: 2. Twos: 3. Threes: TOTAL 12 15 1. Ones: 1. Ones: 3 1. Ones: 3 2. Twos: 2. Twos: 2. Twos: 12 15 3. Threes: 3. Threes: 3. Threes: TOTAL: TOTAL: 3 TOTAL Dice Throw #1 : 2 1 6 2 3 Dice Throw #1: 5 6 1 4 3 Dice Throw #1: 13464 Dice to throw: 1 3 4 5 Dice to throw: 1 2 3 4 Dice to throw: 1 2 3 4 5 Dice Throw #2: 2 1 4 1 2 Dice Throw #2: 35533 Dice Throw #2: 36654 Dice to throw: 1 3 5 Dice Throw #3 : 1 1 4 1 3 Use in row: 1 Score of 3 saved in Dice to throw: 2 3 Dice Throw #3: 33133 Use in row: 3 score of 12 saved in Dice to th Dice Throw #3: 55543 Use in row: 2 Score of 0 saved in row: 1 2 3 4 5 row 1 (Ones) row 3 (Threes) row 2 (Threes)

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago