Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java question please Im working on a project and I think Im getting close but looking for a little push over the finish line. I

Java question please Im working on a project and I think Im getting close but looking for a little push over the finish line.

I am creating a project that simulates rolling dice. Normal dice have 6 sides, and are frequently rolled in pairs, so 2 dice with 6 sides results can range from 2 to 12. For this project, the user will specify the number of sides on a die, how many dice, and how many times to roll those dice.

Create an array to count how many times each possible result was rolled. In the normal 2 dice of 6 sides, the array would need to count how many times a total of 2 was rolled, how many times a total of 3 was rolled, how many times a total of 4 was rolled, etc.

Display the results, by displaying the counts for each result. In addition, as you go through the array to display the number of times each result was rolled, add up those values to verify that the total does indeed match the number of rolls requested by the user.

HERE IS MY MAIN CLASS with my code so far

import java.util.*;

public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); Random random = new Random(); int[] freqency = new int[7]; //face of dice index goes based upon user input(will not be [7] int sideOfDie, numberOfDice, numberOfRolls;

System.out.print("How many sides on a die? "); sideOfDie = stdIn.nextInt(); System.out.print("How many dice shall I roll? "); numberOfDice = stdIn.nextInt(); System.out.print("How many times shall I roll the dice? "); numberOfRolls = stdIn.nextInt(); System.out.println("Number of times each total occured: ");

for (int i = 1; i

for (int j = 1; j

}//end main

}//end class

Here is what the output will look like;

image text in transcribed

How many sides on a die? 9 How many dice shall I roll? 4 How many times shall I rol1 the dice? 1000 Number of times each total occurred: result 4 result S result 6 result 7 result 8 result 9 result 10 result 11 result 12 result 13 result 14 result 15 result 16 result 17 result 18 result 19 result 20 Total1000 BUILD SUCCESSFUL (total time: 12 seconds) times rolled 1 times rolled 3 times rolled 20 times rolled 29 times rolled 51 times rolled 86 times rolled 11S times rolled 130 times rolled 136 times rolled 136 times rolled 112 times rolled 81 times rolled 52 time r 11ed 23 times rolled 15 times rolled 10 times rolled 0 Add up these values And check the total

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 Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What is a new-venture team?

Answered: 1 week ago

Question

Define and measure service productivity.

Answered: 1 week ago