Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that acts as a simple \"slot machine\". The user starts with 100

ID: 3612246 • 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;

nextInt(3) results in the first 3 integers 0,1,2. We donot need 0 so we just add 1 to the end so we will now get a 1,2,or3.
Must address all parts of this question to get"lifesaver." Should ask if it wants to run again! Please makethis as simple as you can make, because I need to understandit!

Thanks for helping me out!

Explanation / Answer

please rate - thanks easy enough import java.util.*; import javax.swing.*; import java.lang.*; public class slotmachine2 { public static void main(String []args) { Random number = new Random(); int pull1,pull2,pull3; String response,mess; char c; int tokens,i,plustokens=0; int won; do { tokens=100; response = JOptionPane.showInputDialog(null, "You have "+tokens+"tokens Pull? "); c = response.charAt(0); while((c=='Y'||c=='y')&&(tokens>0)) {won=0; tokens--; pull1=number.nextInt(3) +1; pull2=number.nextInt(3) +1; pull3=number.nextInt(3) +1; if(pull1==pull2&&pull2==pull3)    { won=1;       if(pull1==1)           plustokens=4;        else if(pull2==2)           plustokens=8;        else           plustokens=12;        tokens+=plustokens;    } mess="["+pull1+"]["+pull2+"]["+pull3+"] "; if(won==1)    mess+="You won "+plustokens+" tokens!"; else    mess+="You lost"; JOptionPane.showMessageDialog(null,mess); response = JOptionPane.showInputDialog(null, "You have "+tokens+"tokens Pull? "); c = response.charAt(0);    } response = JOptionPane.showInputDialog(null, "Thanks for playing Play again?"); c = response.charAt(0); }while(c=='y'||c=='Y'); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote