simulate a pair of dice.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import java.util.*;
  2. /**
  3. * Created by leon on 11/6/17.
  4. */
  5. public class Simulation{
  6. private int noDice;
  7. private int diceRoll;
  8. Bin bin = new Bin();
  9. public Simulation(int noDice, int diceRoll){
  10. this.noDice = noDice;
  11. this.diceRoll = diceRoll;
  12. }
  13. public static void main(String[]args){
  14. }
  15. public void simMill(){
  16. Simulation simmy = new Simulation(2,1_000_000);
  17. Dice dice1 = new Dice();
  18. for (int x = 1_000_000; x >= 0 ; x--){
  19. Integer sum = dice1.roll(2);
  20. // System.out.println(sum);
  21. bin.counter(sum);
  22. }
  23. //print result
  24. printer();
  25. }
  26. public void printer(){
  27. Bin bin1 = new Bin();
  28. for (int x = 2; x <= 12; x++){
  29. float y = 1_000_000;
  30. float z = (bin.getValue(x)/y)*(float)100.0 ;
  31. StringBuilder star = new StringBuilder();
  32. while (z > 0){
  33. star.append("*");
  34. z--;
  35. }
  36. String s = star.toString();
  37. System.out.printf( "%3d : %7s: %.2f %s\n " , x, bin.getValue(x),
  38. bin.getValue(x)/y, s);
  39. }
  40. }
  41. public void simulation()
  42. {
  43. Scanner scanner = new Scanner(System.in);
  44. Scanner close = new Scanner(System.in);
  45. Dice dice = new Dice();
  46. boolean result = true;
  47. while(result == true){
  48. System.out.println("How many dice would you like to roll?");
  49. int die= scanner.nextInt();
  50. if (die == 1){
  51. System.out.println("You rolled a " + dice.roll(die) + ".");} else
  52. if (die > 1){
  53. System.out.println("The sum of your rolls is: " + dice.roll(die) + ".");
  54. } else
  55. if (die == 0){
  56. System.out.println("All your base are belong to us.");
  57. } else
  58. if (die < 0){
  59. System.out.println("No.");
  60. }
  61. System.out.println("do you want to exit? Yes or No");
  62. String exit = close.nextLine();
  63. if (exit.equalsIgnoreCase("No")) {
  64. continue;
  65. } else
  66. if (exit.equalsIgnoreCase("Yes")){
  67. break;
  68. } else {
  69. System.out.println("*Not a valid input*");
  70. }
  71. }
  72. printer();
  73. }
  74. }