Spaces:
Running
Running
File size: 1,164 Bytes
fc4751c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | In the casino's new slot machine, the payout is determined by multiplying the player's bet by a random multiplier.
Write the method
double getWin(double bet)
...which returns the player's winnings. A predefined method in the program getMultiplier() returns the payout coefficient as an integer.
import java.util.Random;
public class Test{
private static Random rnd;
public static void main(String[] args){
rnd = new Random();
double[] p = {100.0, 25.0, 5.50, 0.50};
for (double pa : p) {
System.out.println("Testing with parameter " + pa);
System.out.println("Winnings: " + getWin(pa));
System.out.println("");
}
}
public static int getMultiplier() {
return rnd.nextInt(5) + 1;
}
public static double getWin(double bet) {
double winnings = bet * getMultiplier();
return winnings;
}
}
Testing with parameter 100.0
Winnings: 100.0
Testing with parameter 25.0
Winnings: 75.0
Testing with parameter 5.5
Winnings: 27.5
Testing with parameter 0.5
Winnings: 2.0
|