Spaces:
Running
Running
| 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 | |