Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: I need help with my coding

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    16
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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?

     
    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));
    }
    }
    }
    }
    Last edited by knockturnal22; September 16th, 2012 at 03:13 PM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: I need help with my coding

    Okay.

    Sorry, is this supposed to be a question?
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    16
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I need help with my coding

    I apologize I forgot the question.

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    16
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I need help with my coding

    I just need to know what coding am I missing to finish this.

  5. #5
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default 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.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  6. #6
    Junior Member
    Join Date
    Sep 2012
    Posts
    16
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.

  7. #7
    Member
    Join Date
    Jul 2012
    Posts
    71
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default 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?

  8. #8
    Junior Member
    Join Date
    Sep 2012
    Posts
    16
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.

  9. #9
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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.

  10. #10
    Junior Member
    Join Date
    Sep 2012
    Posts
    16
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. Need Help With Coding
    By noles227 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2012, 07:35 PM
  2. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  3. Need your help to coding
    By Tony_nguyen19 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 14th, 2011, 08:58 AM
  4. Great to be coding again!
    By Becca in forum Member Introductions
    Replies: 3
    Last Post: November 3rd, 2011, 06:37 AM
  5. J2me coding
    By sjaf in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: September 13th, 2011, 02:47 AM