Saturday

March 28, 2015

March 28, 2015

Posted by **Joel Borja** on Sunday, July 14, 2013 at 5:59pm.

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 -
**MathMate**, Sunday, July 14, 2013 at 7:13pmYou 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 -
**adams**, Wednesday, February 12, 2014 at 5:06pmWrite 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.

**Answer this Question**

**Related Questions**

math - i'm supposed to make an equation going off of this problem.. it is ...

Algebra - This question deals with Exponential Growth and Decay Test. Question:...

Statistics - Two dice are tossed. What is the probability that the sum of both ...

Programming Logic - I need to create a flowchart/psuedocode for a dice game that...

Computer Science Java - I have to write program for a dice game and use a ...

Math - Consider the following experiment. Start by tossing 30 dice.Then remove ...

math - Two dice are rolled. Find the odds that the score on the dice is either 7...

Stats HELP PLEASE - The game of Yahtzee is played with five fair six-sided dice...

drawing - Two dice are rolled. What is the probability of rolling a total of ...

math - 3 fair dice are tossed. Find the probability of dice showing at most one ...