Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP FIRST FILE /** * This class simulates rolling a pair of dice 10,000 times and counts the * number of times doubles of

PLEASE HELP

FIRST FILE\

/** * This class simulates rolling a pair of dice 10,000 times and counts the * number of times doubles of are rolled for each different pair of doubles. */ import java.util.Random; //to use the random number generator public class DiceSimulation { static final int NUMBER = 10000; //the number of times to roll the dice //a random number generator used in simulating rolling a dice static Random generator = new Random();

static int die1Value; // number of spots on the first die static int die2Value; // number of spots on the second die static int count = 0; // number of times the dice were rolled static int ones = 0; // number of times double one is rolled static int twos = 0; // number of times double two is rolled static int threes = 0; // number of times double three is rolled static int fours = 0; // number of times double four is rolled static int fives = 0; // number of times double five is rolled static int sixes = 0; // number of times double six is rolled

public static void main(String[] args) { //ENTER YOUR METHOD CALLS HERE } public static void rollDiceAndTabulateWhile() { //Complete task 2 here } public static void rollDiceAndTabulteDoWhile() { //Complete task 3 here } public static void rollDiceAndTabulteFor() { //Complete task 4 here } public static void summarizeResults() { System.out.println("You rolled double ones " + ones + " out of " + NUMBER + " rolls."); System.out.println("You rolled double twos " + twos + " out of " + NUMBER + " rolls."); System.out.println("You rolled double threes " + threes + " out of " + NUMBER + " rolls."); System.out.println("You rolled double fours " + fours + " out of " + NUMBER + " rolls."); System.out.println("You rolled double fives " + fives + " out of " + NUMBER + " rolls."); System.out.println("You rolled double sixes " + sixes + " out of " + NUMBER + " rolls."); } }

SECOND FILE

import java.util.Random; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */

/** * * @author cristy */ public class Dice { private int die1; private int die2; public Dice() { die1 = 1; die2 = 1; } public void rollDice() { Random myRan = new Random(); die1 = myRan.nextInt(6) + 1; die2 = myRan.nextInt(6) + 1; } public String toString() { return "You rolled a ..." + die1 + " and " + die2; } }

INSTRUCTUION

Task #1 Complete the Dice Class

In the domain class, Dice, add two accessor methods that will return the values of die1 and die2, respectively.

Task #2 Use the while- loop

In the driver class, DiceSimulation, within the method rollDiceAndTabulateWhile(), do the following:

Create an instance of the Dice domain class

Create a while-loop that will keep simulating the roll of dice object just created.

Within the loop, check the value of the 2 die just rolled. If there are duplicates, count the dice into the appropriate counter. Make sure to use an if-statement to determine if there are any of these combinations of die values:

ones -- number of times double one is rolled

twos -- number of times double two is rolled

threes - number of times double three is rolled

fours - number of times double four is rolled

fives - number of times double five is rolled

sixes - number of times double six is rolled

Inside the rollDiceAndTabulateFor() method also call the clearCounters() method at the beginning, and the summarizeResults() method at the end. IMPORTANT: Prior to calling the summarizeResults(), print a title stating the type of loop being used for these results. Add some ******* to the title, to serve as separators between loop results

Once this is complete, go to the main method and call the rollDiceAndTabulateFor() method.

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

What is centering, why would you use it, and how is it done?

Answered: 1 week ago

Question

Which data directive creates a 1 6 - bit signed integer variable?

Answered: 1 week ago

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago