# Java programming- simulation of rolling dice

posted by .

This is what i have so far. I'm supposed to simulate the 4 dice tossed 1 million times . (so a total of 4 million) I'm trying to get the first die(If I can figure out the first one then I can figure out the other 3. So the trouble I am having is that I cant get the face in the output to show the numbers I appointed in the first array die1. How do I get the numbers for die1 to show on the output. Also the frequency is way over the 1 million. How do I get it so that my frequency to stay in the 1 million range (or any other number that the user may input. Really need help for this. Its due tomorrow but I have been working hard at this for the past week. Help would be appreciated! Thank you

import java.util.Random;
import java.util.Scanner;
public class Game_Of_Dice {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Random rand = new Random();

int [] die1= {1,8,11,14,19,22,27,30,35,38,41,48}; //This sets up the array for each of the die.
int [] die2 = {2,7,10,15,15,23,26,31,34,39,42,47};//Goes from 0-11 in each of the die.
int [] die3 = {3,6,12,13,17,24,25,32,36,37,43,46};
int [] die4 = {4,5,9,16,20,21,28,29,33,40,44,45};
int temp, times;

System.out.println("We will simulate rolling 4 different dice.");
System.out.println("This will test the hypothesis of the 'go first dice' ");
System.out.println("We will now roll the first die one million times. Please enter the number one million.");
times = input.nextInt();

for (int i = 0; i < times; i++)
{
temp = rand.nextInt(12);
die1[temp]++;
}

System.out.println("Face\tFrequency"); //This will print out the face and frequency of the die.
for (int i = 0; i < 12; i++){
System.out.println(i+1 + "\t" + die1[i]);

}

OUTPUT:______________________________________________________________________________________

We will simulate rolling 4 different dice.
This will test the hypothesis of the 'go first dice'
We will now roll the first die one million times. Please enter the number one million.
1000000
Face Frequency
1 82932
2 83881
3 83356
4 83071
5 83618
6 82831
7 83422
8 83228
9 83467
10 83284
11 83398
12 83806

}
}

• Java programming- simulation of rolling dice -

You have made the arrays die1...die4 to do two things:
1. as a counter (accumulator) for the frequency, and
2. as the value of the face.
This is an impossible task, and that explains why the total adds up to more than a million.

I suggest you make the following changes:
1. Add a constant integer array, such as pips1[], to store the value of each face.
2. Initialize die1[]...die4[] to zero (which is the default in Java).
Proceed as above. Then the total should add up to 1 million.
Use the pip1[] array to show the value of faces 0-11.
Good luck!

• Java programming- simulation of rolling dice -

Write a program to prompt the user to enter the cost of an item before VAT has been
added. The program should calculate and output the amount of VAT payable and the
total cost of the item including VAT.

VAT is currently charged at 20% and this should be stored as a constant in your
program.

## Similar Questions

1. ### English expression

There is only one die in playing the dice game. They are supposed to work in pairs in the dice game. Which expressions are correct?
2. ### math

i'm supposed to make an equation going off of this problem.. it is supposed to be an exponential equation, but i don't exactly know how i am supposed to do this.. please help:(.. You roll 36 dice and remove the dice with one dot showing. …

The game of Yahtzee is played with five fair six-sided dice. A turn consists of rolling all five dice, selecting the ones you want to keep, re-rolling the rest, and then doing this one more time, if necessary. You need to match certain …
4. ### Algebra

This question deals with Exponential Growth and Decay Test. Question:Consider the following:Start by tossing 30 dice. Then remove the dice that show 5s and 6s and toss the remaining dice. Repeat this process until you only have 2 dice …
5. ### Programming Logic

I need to create a flowchart/psuedocode for a dice game that give you 2 rolls with 5 dice, 3 rolls per game. the computer will roll the 4 dice and calculate your score. my question is...do i need to repeat this 3 times and can i use …
6. ### Algebra

You are a contestant on a game show and have the chance to win a car by rolling 5 dice. Each die has three sides that say CAR and three sides that are blank. In order for you to win the car you CAR on all five dice. You have three …
7. ### probability

Two six-sided dice each have the numbers 1 through 6 on their faces. Neither die is fair, but they are both weighted the same. The probability of rolling a certain number on one die is given in the table below: # 1 2 3 4 5 6 probability …
8. ### Statistics

Two dice are tossed. What is the probability that the sum of both dice is a prime number?
9. ### Probability

You roll two five-sided dice. The sides of each die are numbered from 1 to 5. The dice are “fair" (all sides are equally likely), and the two die rolls are independent. Part (a): Event A is “the total is 10" (i.e., the sum of the …
10. ### math

If two dice are rolled and their faces noted, find each of the following probabilities: a) the sum of the two dice is 8 b) both dice show even numbers c) the sum of the two dice is 8 OR both dice show even numbers d) the sum of the …

More Similar Questions