I need help with my coding
I've been working on this for a few days now and I'm stuck and burned out. I'm working on a project for a class and trying to create a basic and simple slot machine for my presentation. This is what I have below. What coding am I missing to finish this?
Code Java:
import java.io.PrintStream;
import java.util.Random;
import java.util.Scanner;
public class SlotMachineProject
{
public static int balance = 0 ;
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int play = 0;
int cashOut = 0;
boolean done = false ;
Random generator = new Random();
//Copy the random assignments to slots to inside the loop so you get different "pulls" of the machine each time
int slot1 = generator.nextInt(10);
int slot2 = generator.nextInt(10);
int slot3 = generator.nextInt(10);
System.out.println("Your Current Balance is: " + balance);
// I think conditions in a while are confusing. I would I simplify it to this:
//
// while ( !done )
//
// Then set boolean variable done correctly within the loop using if on cashOut.
//
while ((cashOut > 0) || (play <= 0))
{
// stop playing immediately without looping
System.out.println("\nType 1 to start the slot machine or 0 to stop playing.");
cashOut = scan.nextInt();
// I need to put in an if to set done = true when cashOut is 0.
// I'm confused. I put spaces in here so that it is clear that it is more than
// one number being printed.
System.out.println("Result is: " + slot1 + "," + slot2 + " " + slot3);
if ((slot1 == slot2) && (slot1 == slot3))
{
// I need to change balance, play or both here to reflect winnings.
System.out.println("Congradulations, you have won: " + play);
System.out.println("\nCurrent Balance is: " + (play + balance));
}
else if (((slot1 == slot2) && (slot1 != slot3)) || ((slot2 == slot3) && (slot2 != slot1)) || ((slot3 == slot1) && (slot3 != slot2)))
{
System.out.println("Congradulations, you have won." + play);
System.out.println("\nCurrent Balance is: " + (play + balance));
}
else if ((slot1 != slot2) && (slot1 != slot3) && (slot2 != slot3))
{
System.out.println("\nCurrent Balance is: " + (cashOut - balance));
}
}
}
}
Re: I need help with my coding
Okay.
Sorry, is this supposed to be a question?
Re: I need help with my coding
I apologize I forgot the question.
Re: I need help with my coding
I just need to know what coding am I missing to finish this.
Re: I need help with my coding
Are you writing a program which controls Russia's nuclear reactors? If so, yes you've got a lot of coding to do.
How can we possibly tell that if we don't know your goals? Please ask a specific question.
Re: I need help with my coding
I'm new at this. I'm trying to create a slot machine; very basic and simple slot machine.
Re: I need help with my coding
what is "while(cashout > 0 || play <=0)" that has potential to be an infinite loop.... when would play ever be less than 0? also where is ur code that sets the balance & when is the boolean done ever used?
Re: I need help with my coding
I was getting advice from a classmate and that's where I got stuck at. I do not want it to be infinite as you mentioned. I'm trying to figure out how to have it when type "0" it ends. really do know what code to use for the balance and boolean. I'm new at this.
Re: I need help with my coding
Have you gone through the Java Tutorials or your text book on this? Next, have you considered making an appointment with your instructor or a tutor to get you up and running with Java? This can help you much more than a forum is able to do.
Re: I need help with my coding
If someone can guide me to where I can go to fix my problems would be helpful. My instructor gave me notes on what to do. I'm just trying to interrupt the notes myself.