Write a program that acts as a simple \"slot machine\". The user starts with 100
ID: 3612142 • Letter: W
Question
Write a program that acts as a simple "slot machine". The user starts with 100 tokens and with each pullof the handles loses one token. The computer spins threewheels each consisting of the numbers 1,2, and 3. If allthree of the numbers are 1 the user gets 4 tokens; if all three are2 the user gets 8 tokens; if all three are 3 the user gets 12tokens. Program output should look similar to
You have 100 tokens Pull? Y
[1] [3] [2]
You lost
You have 99 tokens Pull? Y
[2] [2] [2]
you won 8 tokens!
You have 106 tokens Pull? n
Thanks for playing
Must use JOptionPane! Error messages! programmust stop if the user has no token left!
you can use the random number generator in the book -remember that
x= random(); gives you a random number between 0 andone. To get a random number which is an integer 1,2,3 youwould use:
x = (( int) (random()*10 +.5)) +1;
you can also use a function in the utility class called nextInt(); To use this you need to import the utilityclass.
import java.util.*
Then in the main you need to creatan object of Random:
Random number = new Random()
then you can use
num= number.nextInt(3) +1;