Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to assign a random number a string value in my program
    text
    copied!<p>as the title suggests I am doing a program for homework that is a slot machine. I have searched around and I am pretty satisfied that the program works correctly enough for me. The problem Im having is on top of generating the random numbers, I am supposed to assign values for the numbers 1-5 (Cherries, Oranges, Plums, Bells, Melons, Bars). Then I am to display the output instead of the number when my program runs. Can anyone get me pointed in the right direction on how to do this please?</p> <pre><code>import java.util.Random; import java.util.Scanner; public class SlotMachineClass { public static void main(String[] args) { Scanner input = new Scanner(System.in); int Coins = 1000; int Wager = 0; System.out.println("Steve's Slot Machine"); System.out.println("You have " + Coins + " coins."); System.out.println("Enter your bet and press Enter to play"); while (Coins &gt; 0) { int first = new Random().nextInt(5)+1; int second = new Random().nextInt(5)+1; int third = new Random().nextInt(5)+1; Wager = input.nextInt(); if(Wager &gt; Coins) Wager = Coins; System.out.println(first + " " + second + " " + third); if(first == second &amp;&amp; second == third) { Coins = Coins + (Wager * 3); System.out.println("You won " + (Wager * 3) + "!!!!" + " You now have " + Coins + " coins."); System.out.println("Enter another bet or close program to exit");} else if((first == second &amp;&amp; first != third) || (first != second &amp;&amp; first == third) || (first != second &amp;&amp; second == third)) { Coins = Coins + (Wager * 2); System.out.println("You won " + (Wager * 2) + "!!!" + " You now have " + Coins + " coins."); System.out.println("Enter another bet or close program to exit");} else {Coins = Coins - Wager; System.out.println("You Lost!" + "\nPlay Again? if so Enter your bet.");} } while (Wager == 0) { System.out.println("You ran out of coins. Thanks for playing."); } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload