Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.weebly.chemicalstudios.src;
- import java.util.Random;
- public class Main {
- private static int count = 1;
- private static Random random = new Random();
- private static int playTry = 0;
- private static int chance = 5;
- private static Prize[] prizes = { new Prize(55, "$4"),
- new Prize(111, "$4"), new Prize(707, "$7"), new Prize(360, "$7"),
- new Prize(12244, "$100"), new Prize(19087, "$100"),
- new Prize(648975, "$10,000"), new Prize(5153632, "$1,000,000"),
- new Prize(175223510, "the grand prize") };
- public static void main(String[] args) {
- System.out.println("After playing...");
- genOdds(prizes);
- }
- /*
- * Generates an odd between 0 and the probablity, counts up if
- * it's not the correct number, stops counting prints then restarts if it is
- * the correct number
- */
- public static void genOdds(Prize[] prizes) {
- for (int i = 0; i < prizes.length; i++) {
- count = 1;
- playTry = random.nextInt(prizes[i].getProbability());
- while (playTry != chance) {
- playTry = random.nextInt(prizes[i].getProbability());
- ++count;
- }
- System.out.println(count + " times, you got "
- + prizes[i].getPrize());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement