Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. /**
  2. * Description for 5.04 Dice Probability project
  3. *
  4. * @author (Your Name)
  5. * @version (The Date)
  6. */
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10. public class DiceProbability
  11. {
  12. public static void main(String[] args)
  13. {
  14. //Declare and initialize variables and objects
  15. Scanner in = new Scanner(System.in);
  16. Random randNumber = new Random();
  17.  
  18. int match = 0; //Number of times sum of dice matches the current sum
  19. int die1, die2; //Random generated numbers
  20.  
  21.  
  22. //Input: ask user for number of rolls and number of sides on a die
  23.  
  24. System.out.println("How many rolls would you like? ");
  25. int rolls = in.nextInt();
  26.  
  27. //If amount of sides are to be chosen:
  28. //System.out.println("How many sides would you like? ");
  29. //int sides = in.nextInt();
  30. int sides = 11;
  31.  
  32. //Print heading for output table
  33. System.out.println("Number of Rolls: " + rolls);
  34. System.out.println(" Sum of Dice Probability");
  35.  
  36.  
  37. //***************************************************************************************
  38. //Using nested loops, cycle through the possible sums of the dice.
  39. //Roll the dice the given number of times for each sum.
  40. //Count how many times the sum of the dice match the current sum being looked for.
  41. //***************************************************************************************
  42.  
  43. //Loop to increment through the possible sums of the dice
  44.  
  45.  
  46. int randNum = 0;
  47.  
  48. for(int n = 2; n <= 22; n++)
  49. {
  50. randNum = randNumber.nextInt(sides);
  51. System.out.println(n + "s");
  52. }
  53.  
  54.  
  55. //Loop to throw dice given number of times
  56.  
  57.  
  58.  
  59.  
  60. //Randomly generate values for two dice
  61.  
  62.  
  63.  
  64.  
  65. //Check if the sum of dice is equal to the given sum
  66.  
  67.  
  68.  
  69.  
  70.  
  71. //After all throws, calculate percentage of throws that resulted in the given sum
  72. //Print results
  73.  
  74.  
  75.  
  76.  
  77. } //end main
  78. }//end class DiceProbability
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement