Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Description for 5.04 Dice Probability project
- *
- * @author (Your Name)
- * @version (The Date)
- */
- import java.util.Random;
- import java.util.Scanner;
- public class DiceProbability
- {
- public static void main(String[] args)
- {
- //Declare and initialize variables and objects
- Scanner in = new Scanner(System.in);
- Random randNumber = new Random();
- int match = 0; //Number of times sum of dice matches the current sum
- int die1, die2; //Random generated numbers
- //Input: ask user for number of rolls and number of sides on a die
- System.out.println("How many rolls would you like? ");
- int rolls = in.nextInt();
- //If amount of sides are to be chosen:
- //System.out.println("How many sides would you like? ");
- //int sides = in.nextInt();
- int sides = 11;
- //Print heading for output table
- System.out.println("Number of Rolls: " + rolls);
- System.out.println(" Sum of Dice Probability");
- //***************************************************************************************
- //Using nested loops, cycle through the possible sums of the dice.
- //Roll the dice the given number of times for each sum.
- //Count how many times the sum of the dice match the current sum being looked for.
- //***************************************************************************************
- //Loop to increment through the possible sums of the dice
- int randNum = 0;
- for(int n = 2; n <= 22; n++)
- {
- randNum = randNumber.nextInt(sides);
- System.out.println(n + "s");
- int counter = 0;
- for (int i = 0; i <1000; i++){
- if (randNum + randNum == n)
- counter++;
- }
- }
- //Loop to throw dice given number of times
- //Randomly generate values for two dice
- //Check if the sum of dice is equal to the given sum
- //After all throws, calculate percentage of throws that resulted in the given sum
- //Print results
- } //end main
- }//end class DiceProbability
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement