Results 1 to 3 of 3
  1. #1
    danthegreat is offline Member
    Join Date
    Sep 2011
    Location
    Washington DC
    Posts
    51
    Rep Power
    0

    Default Slot Machine Game

    hi, it is me again. Need some help with a program of mine. I have mostly finished it, just need some help with the errors i am receiving

    Java Code:
    import java.util.*;
    public class ansher_slots {
        public static void main(String [] args){
            Scanner keyboard =new Scanner(System.in);
            int num=0;
            int bet = 0;
            int won_amount=0;
            int loopvar=1;
            
            System.out.println("The World Series of Slots Machine! It's Game Time!");
            System.out.print("How many tokens are you buying? ");
            int tokens = keyboard.nextInt();
            
    [B]        do{[/B]
    
    
    
    [B]        System.out.print("You have " + tokens + " tokens. Would you like to play? (y/n): ");[/B]
    [B]        String play_question = keyboard.nextLine();[/B]
            
    
    
            
            if(play_question=="y"){
                loopvar=2;
                do{
                    System.out.print("How much would you like to bet? ");
                    bet = keyboard.nextInt();
    
    
                    
                    if(bet>tokens || bet<0){
                        System.out.print("ERROR: You entered more tokens than you have or a negative number.");
                        num=1;
                    }
                }while(num==1);
                
                
                System.out.print("You have bet " + bet + " tokens...Buena Suerte!");
                
                int ran1=spin();
                int ran2=spin();
                int ran3=spin();
                
                System.out.println("SPIN:  [" + ran1 + "] [" + ran2 + "] [" + ran3+ "]");
                
                won_amount=determineWin(bet, ran1, ran2, ran3);
                tokens = tokens + won_amount;
                if(won_amount>0){
                    System.out.println("You won " + won_amount + " tokens!! WOW!!");
                }
                else if(won_amount==0){
                    System.out.println("Sorry Big shot, You didn't win anything..Better luck next time!");
                }
                
            }
            else{
                System.exit(-1);
            }
            
            }while(loopvar==2);
            
            
        }
        
        public static int determineWin(int bet, int ran1, int ran2, int ran3){
            if(ran1==7 && ran2==7 && ran3==7){
                return bet*3;
                
            }
            else if(ran1==2 && ran2==2 || ran2==2 && ran3==2 || ran1==2 && ran3==2){
                return bet*2;
                
            }
            else if(ran1==5 || ran2==5 || ran3==5){
                return bet;
            }
            else{
                return 0;
            }
            
    
    
            
            
        }
        
        public static int spin(){
            Random randGen= new Random();
            int random_number=0;
            
            random_number=randGen.nextInt(9)+1;
            return random_number;
            
            
        }
    
    
    }
    for some reason, when it gets to the bolded part, I cannot enter any imput when debugging. Does anyone know what is wrong..?

    This is current output:
    The World Series of Slots Machine! It's Game Time!
    How many tokens are you buying? 125
    You have 125 tokens. Would you like to play? (y/n):


    When I try to type, nothing happens...

  2. #2
    danthegreat is offline Member
    Join Date
    Sep 2011
    Location
    Washington DC
    Posts
    51
    Rep Power
    0

    Default Re: Slot Machine Game

    so I added Keyboard.nextline(); befre the next "nextInt()" and it seemed to work! But when it gets to this part:
    Java Code:
    [FONT=monospace]        
    if(play_question=="y"){[/FONT]
                loopvar=2;            
    do{                
    System.out.print("How much would you like to bet? ");                
    bet = keyboard.nextInt();
    It is terminated for some reason, this is output:
    The World Series of Slots Machine! It's Game Time!
    How many tokens are you buying? 125
    You have 125 tokens. Would you like to play? (y/n): y

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default Re: Slot Machine Game

    if(play_question=="y"){
    You should use the equals() method when comparing String objects, not the == operator.

Similar Threads

  1. Replies: 1
    Last Post: 06-02-2011, 10:29 AM
  2. Replies: 0
    Last Post: 02-07-2011, 02:27 PM
  3. Slot Machine Project
    By nemoisback66 in forum New To Java
    Replies: 11
    Last Post: 11-17-2010, 04:20 PM
  4. Getting name/ip of a machine
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-02-2008, 08:11 PM
  5. Replies: 0
    Last Post: 07-25-2007, 10:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •