Advertisement
ChemicalStudios

Main.java

Feb 22nd, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. package com.weebly.chemicalstudios.src;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Main {
  6.  
  7.     private static int count = 1;
  8.  
  9.     private static Random random = new Random();
  10.  
  11.     private static int playTry = 0;
  12.  
  13.     private static int chance = 5;
  14.  
  15.     private static Prize[] prizes = { new Prize(55, "$4"),
  16.             new Prize(111, "$4"), new Prize(707, "$7"), new Prize(360, "$7"),
  17.             new Prize(12244, "$100"), new Prize(19087, "$100"),
  18.             new Prize(648975, "$10,000"), new Prize(5153632, "$1,000,000"),
  19.             new Prize(175223510, "the grand prize") };
  20.  
  21.     public static void main(String[] args) {
  22.  
  23.         System.out.println("After playing...");
  24.         genOdds(prizes);
  25.     }
  26.  
  27.     /*
  28.      * Generates an odd between 0 and the probablity, counts up if
  29.      * it's not the correct number, stops counting prints then restarts if it is
  30.      * the correct number
  31.      */
  32.     public static void genOdds(Prize[] prizes) {
  33.         for (int i = 0; i < prizes.length; i++) {
  34.             count = 1;
  35.             playTry = random.nextInt(prizes[i].getProbability());
  36.             while (playTry != chance) {
  37.                 playTry = random.nextInt(prizes[i].getProbability());
  38.                 ++count;
  39.             }
  40.             System.out.println(count + " times, you got "
  41.                     + prizes[i].getPrize());
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement