Results 1 to 13 of 13
  1. #1
    Qwertyness_ is offline Member
    Join Date
    Mar 2013
    Location
    Hermon, Maine USA
    Posts
    7
    Rep Power
    0

    Default Skipping code on second run through?

    Java Code:
        public static void SlotInter(int bet1) {
        	//int balance =10;
        	
        	//if (balance < 10) {
        		//balance = 10;
        	//}
        	    if (bet1 <= balance) {
                    System.out.println("You have bet a total of $" + bet1);
                    System.out.println("Enter 's' to spin.  Enter 'b' to rebid.");
                    Scanner spin = new Scanner(System.in);
                    char answer2 = spin.findWithinHorizon(".",  0).charAt(0);
                        if (answer2 == 's') {
                        	balance = balance - bet1;
                	        Random spinner = new Random();
                	        int spinland;
                	            spinland = spinner.nextInt(100);
                	                if (spinland >= 95) {
                	        	        balance = bet1 * 10 + balance;
                	        	        System.out.println("Jackpot!!!!!!!. Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland >= 90 && spinland < 95) {
                	                	balance = bet1 * 5 + balance;
                	                	System.out.println("Wow, thats a lot of dough! Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland >= 75 && spinland < 90) {
                	                	balance = bet1 * 2 + balance;
                	                	System.out.println("You doubled your bet! Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland >= 50 && spinland < 75) {
                	                	balance = bet1 * 1 + balance;
                	                	System.out.println("Well, at least you made your money back.  Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland < 50) {
                	                	balance = bet1 * 0 + balance;
                	                	System.out.println("Oops, better luck next time!  Your new balance is $" + balance);
                	                }
                	         System.out.println("Would you like to spin again or rebid? s/b?");
                	         Scanner second = new Scanner(System.in);
                	         char second1;
                	         second1 = second.findWithinHorizon("." , 0).charAt(0);
                	         
                	         if (second1 == 's' || second1 == 'S') {
                	        	 SlotInteract(balance, bet1);
                	         }
                	         
                	         if (second1 == 'b' || second1 == 'B') {
                	        	 SlotPlay();
                	         }
                        }
                
                
                if (answer2 == 'b') {
                	SlotPlay();
                }
            }
        	    
        	if (balance < bet1) {
        		System.out.println("You do not have enough money for that bet, please bet again.");
        		SlotPlay();
        	}
        }
    If someone chooses the rebid option in this code, the method SlotPlay is called and the declaration of balance is rerun. This resets any previous gains the player had made before they rebet.
    How would I skip the declaration if the code had already been run once so that the balance is not reset? I have tried putting the value declaration of balance into an if statement but it can't check the value
    if balance hasn't been declared yet. How would I do this without making another copy of all the code for the second run through?
    Last edited by Qwertyness_; 03-07-2013 at 01:27 PM.

  2. #2
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: Skipping code on second run through?

    should lines 56-58 be an ElseIf attached to the bottom of line 59? right now you have it inside that IF structure starting on line 12 which will cause it to never be reached...

    just my first glance...

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Skipping code on second run through?

    Hi Qwertyness_,

    A while or do-while loop would be a better option for this code instead of calling SlotPlay() which, from a previous thread, is the calling method.
    Can you provide the remaining code particularly the SlotPlay() and SlotInteract() methods as there may be some additional recommendations.

    Regards.

  4. #4
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: Skipping code on second run through?

    I'm not sure if I understand your question, but did you consider using boolean flags.
    When your method is to be invoked, first check this boolean flag (for example if it is false - set the balance and run the method, if it is true than the code has been already run and you can skip setting balance, just run the method.. Something like:

    Java Code:
    ...
    boolean firstRun = false;
    // declaring balance
    ...
    
    if(!firstRun){
    
        // initializing balance
    
        yourMethod();
    }
    else{
    
        yourMethod();
    }
    
    public void yourMethod(){
        firstRun = true;
        ...
    }
    Again, I'm not sure if this is suitable, because I'm not sure if I understand your intention..

  5. #5
    Qwertyness_ is offline Member
    Join Date
    Mar 2013
    Location
    Hermon, Maine USA
    Posts
    7
    Rep Power
    0

    Default Re: Skipping code on second run through?

    Thanks for the help. I think the boolean flags are what I am looking for. I will try it out in my code.

    As for the methods:

    This is the full logic system I have been using to classify bets

    Java Code:
    public static void SlotPlay() {
        	System.out.println("The starting balance is $10.");
        	System.out.println("Would you like to bet $5, $10, $20, or $50?");
        			
        			Scanner betent = new Scanner(System.in);
        			int bet = betent.nextInt();
        			
        			    if (bet == 5) {
        			    	SlotPlay5();
        			    }
        			    
        			    if (bet == 10) {
        			    	SlotPlay10();
        			    }
        			    
        			    if (bet == 20) {
        			    	SlotPlay20();
        			    }
        			    
        			    if (bet == 50) {
        			    	SlotPlay50();
        			    }
        			
        }
        
        public static void SlotPlay5() {
        	System.out.println("Would you like to play 1, 2, 4, or 8 lines?");
    		Scanner lineread = new Scanner(System.in);
    		int lines = lineread.nextInt();
    		
    		    if (lines == 1) {
    		    	SlotPlay5l1();
    		    }
    		    
                if (lines == 2) {
                	SlotPlay5l2();
    		    }
     
                if (lines == 4) {
                	SlotPlay5l4();
                }
     
                if (lines == 8) {
                	SlotPlay5l8();
                }
        }
        
        public static void SlotPlay10() {
        	System.out.println("Would you like to play 1, 2, 4, or 8 lines?");
    		Scanner lineread = new Scanner(System.in);
    		int lines = lineread.nextInt();
    		
    		if (lines == 1) {
    	    	SlotPlay10l1();
    	    }
    	    
            if (lines == 2) {
    	    	SlotPlay10l2();	    	
    	    }
    
            if (lines == 4) {
    	    	SlotPlay10l4();	
            }
    
            if (lines == 8) {
    	    	SlotPlay10l8();	
            }
        }
        
        public static void SlotPlay20() {
        	System.out.println("Would you like to play 1, 2, 4, or 8 lines?");
    		Scanner lineread = new Scanner(System.in);
    		int lines = lineread.nextInt();
    		
    		if (lines == 1) {
    	    	SlotPlay20l1();
    	    }
    	    
            if (lines == 2) {
    	    	SlotPlay20l2();    	
    	    }
    
            if (lines == 4) {
    	    	SlotPlay20l4();
            }
    
            if (lines == 8) {
    	    	SlotPlay20l8();	
            }
        }
        
        public static void SlotPlay50() {
        	System.out.println("Would you like to play 1, 2, 4, or 8 lines?");
    		Scanner lineread = new Scanner(System.in);
    		int lines = lineread.nextInt();
    		
    		if (lines == 1) {
    	    	SlotPlay50l1();
    	    }
    	    
            if (lines == 2) {
    	    	SlotPlay50l2();	    	
    	    }
    
            if (lines == 4) {
    	    	SlotPlay50l4();
            }
    
            if (lines == 8) {
    	    	SlotPlay50l8();	
            }
        }
        
        public static void SlotPlay5l1() {
        	int bet = 5;
        	SlotInter(bet);
        }
        
        public static void SlotPlay5l2() {
        	int bet = 10;
        	SlotInter(bet);
        }
        
        public static void SlotPlay5l4() {
        	int bet = 20;
        	SlotInter(bet);
        }
        
        public static void SlotPlay5l8() {
        	int bet = 40;
        	SlotInter(bet);
        }
        
        public static void SlotPlay10l1() {
        	int bet = 10;
        	SlotInter(bet);
        }
        
        public static void SlotPlay10l2() {
        	int bet = 20;
        	SlotInter(bet);
        }
        
        public static void SlotPlay10l4() {
        	int bet = 40;
        	SlotInter(bet);
        }
        
        public static void SlotPlay10l8() {
        	int bet = 80;
        	SlotInter(bet);
        }
        
        public static void SlotPlay20l1() {
        	int bet = 20;
        	SlotInter(bet);
        }
        
        public static void SlotPlay20l2() {
        	int bet = 40;
        	SlotInter(bet);
        }
        
        public static void SlotPlay20l4() {
        	int bet = 80;
        	SlotInter(bet);
        }
        
        public static void SlotPlay20l8() {
        	int bet = 160;
        	SlotInter(bet);
        }
        
        public static void SlotPlay50l1() {
        	int bet = 50;
        	SlotInter(bet);
        }
        
        public static void SlotPlay50l2() {
        	int bet = 100;
        	SlotInter(bet);
        }
        
        public static void SlotPlay50l4() {
        	int bet = 200;
        	SlotInter(bet);
        }
        
        public static void SlotPlay50l8() {
        	int bet = 400;
        	    SlotInter(bet);
        	
        }
    And this is the SlotInteract method for spins after spin one..

    Java Code:
        public static void SlotInteract(int balance, int bet1) {
        	 if (bet1 <= balance) {
                 System.out.println("You have bet a total of $" + bet1);
                 System.out.println("Enter 's' to spin.  Enter 'b' to rebid.");
                 Scanner spin = new Scanner(System.in);
                 char answer2 = spin.findWithinHorizon(".",  0).charAt(0);
                     if (answer2 == 's') {
                     	balance = balance - bet1;
             	        Random spinner = new Random();
             	        int spinland;
             	            spinland = spinner.nextInt(100);
             	                if (spinland >= 95) {
             	        	        balance = bet1 * 10 + balance;
             	        	        System.out.println("Jackpot!!!!!!!. Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland >= 90 && spinland < 95) {
             	                	balance = bet1 * 5 + balance;
             	                	System.out.println("Wow, thats a lot of dough! Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland >= 75 && spinland < 90) {
             	                	balance = bet1 * 2 + balance;
             	                	System.out.println("You doubled your bet! Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland >= 50 && spinland < 75) {
             	                	balance = bet1 * 1 + balance;
             	                	System.out.println("Well, at least you made your money back.  Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland < 50) {
             	                	balance = bet1 * 0 + balance;
             	                	System.out.println("Oops, better luck next time!  Your new balance is $" + balance);
             	                }
             	         System.out.println("Would you like to spin again or rebid? s/b?");
             	         Scanner second = new Scanner(System.in);
             	         char second1;
             	         second1 = second.findWithinHorizon("." , 0).charAt(0);
             	         
             	         if (second1 == 's' || second1 == 'S') {
             	        	 SlotInteract(balance, bet1);
             	         }
             	         
             	         if (second1 == 'b' || second1 == 'B') {
             	        	 SlotPlay();
             	         }
                     }
             
             
             if (answer2 == 'b') {
             	SlotPlay();
             }
         }
     	    
     	if (balance < bet1) {
     		System.out.println("You do not have enough money for that bet, please bet again.");
     		SlotPlay();
     	}
     	
    }
    Any further suggestions would be greatly apprecieated!

  6. #6
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Skipping code on second run through?

    I've not got as far as the SlotInteract() method yet, but calling SlotPlay() from within a method which was called by SlotPlay() can get messy.
    I would recommend taking this back to a single go to begin with and work it from there.

    Looking over the initial code, there are a lot of unnecessary methods.
    Going back to SlotPlay(), you could ask the user to input the amount they want to bet as you are currently doing. Next, ask the user how many lines they want to play. Multiply the first value by the second and pass the resulting value directly into SlotInter() which could return the winnings.

    Once this is done you can ask the user if they want to play again, looping through the previous code if they do.

    Regards.

  7. #7
    Qwertyness_ is offline Member
    Join Date
    Mar 2013
    Location
    Hermon, Maine USA
    Posts
    7
    Rep Power
    0

    Default Re: Skipping code on second run through?

    Java Code:
    import java.util.Scanner;
    import java.util.Random;
    
    public class SlotMachine {
    
    	public static void main(String[] args) {
    		System.out.println("Would you like to play SlotSo? Y/N?");
    		char answer1;
    		Scanner answer = new Scanner(System.in);
    		answer1 = answer.findWithinHorizon("." , 0).charAt(0);
    		if (answer1 == 'Y' || answer1 == 'y'){
    			SlotPlay();
    		}
    
            if (answer1 == 'N' || answer1 == 'n') {
            	System.out.println("Thanks for playing SlotSo! Goodbye.");
            }
    
    	}
        public static void SlotPlay() {
        	boolean firstRun = false;	
        	System.out.println("The starting balance is $10.");
        	int balance;
        	if (firstRun = false) {
        		balance = 10;
        	}
        	System.out.println("Would you like to bet $5, $10, $20, or $50?");
        			
        			Scanner betent = new Scanner(System.in);
        			int bet = betent.nextInt();
            System.out.println("Would you like to play 1, 2, 4, or 8 lines?");
                Scanner line = new Scanner(System.in);    
                int lines = line.nextInt();
                
                int fullbet = bet * lines;
                firstRun = true;
                SlotInter(fullbet, balance);
        			
        }
        
    
        public static void SlotInter(int fullbet, int balance) {
        	boolean firstRun = false;
        	
        	Scanner spin = new Scanner(System.in);
                    char answer2 = spin.findWithinHorizon(".",  0).charAt(0);
        	
        	    if (fullbet <= balance) {
                    System.out.println("You have bet a total of $" + fullbet);
                    System.out.println("Enter 's' to spin.  Enter 'b' to rebid.");
                    
                        if (answer2 == 's') {
                        	balance = balance - fullbet;
                	        Random spinner = new Random();
                	        int spinland;
                	            spinland = spinner.nextInt(100);
                	                if (spinland >= 95) {
                	        	        balance = fullbet * 10 + balance;
                	        	        System.out.println("Jackpot!!!!!!!. Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland >= 90 && spinland < 95) {
                	                	balance = fullbet * 5 + balance;
                	                	System.out.println("Wow, thats a lot of dough! Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland >= 75 && spinland < 90) {
                	                	balance = fullbet * 2 + balance;
                	                	System.out.println("You doubled your bet! Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland >= 50 && spinland < 75) {
                	                	balance = fullbet * 1 + balance;
                	                	System.out.println("Well, at least you made your money back.  Your new balance is $" + balance);
                	                }
                	                
                	                if (spinland < 50) {
                	                	balance = fullbet * 0 + balance;
                	                	System.out.println("Oops, better luck next time!  Your new balance is $" + balance);
                	                }
                	         System.out.println("Would you like to spin again or rebid? s/b?");
                	         Scanner second = new Scanner(System.in);
                	         char second1;
                	         second1 = second.findWithinHorizon("." , 0).charAt(0);
                	         
                	         if (second1 == 's' || second1 == 'S') {
                	        	 SlotInteract(balance, fullbet);
                	         }
                	         
                	         if (second1 == 'b' || second1 == 'B') {
                	        	 SlotPlay();
                	         }
                        }
                
                
                if (answer2 == 'b') {
                	SlotPlay();
                }
            }
        	    
        	if (balance < fullbet) {
        		System.out.println("You do not have enough money for that bet, please bet again.");
        		SlotPlay();
        	}
        
        }
        
        public static void SlotInteract(int balance, int bet1) {
        	 if (bet1 <= balance) {
                 System.out.println("You have bet a total of $" + bet1);
                 System.out.println("Enter 's' to spin.  Enter 'b' to rebid.");
                 Scanner spin = new Scanner(System.in);
                 char answer2 = spin.findWithinHorizon(".",  0).charAt(0);
                     if (answer2 == 's') {
                     	balance = balance - bet1;
             	        Random spinner = new Random();
             	        int spinland;
             	            spinland = spinner.nextInt(100);
             	                if (spinland >= 95) {
             	        	        balance = bet1 * 10 + balance;
             	        	        System.out.println("Jackpot!!!!!!!. Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland >= 90 && spinland < 95) {
             	                	balance = bet1 * 5 + balance;
             	                	System.out.println("Wow, thats a lot of dough! Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland >= 75 && spinland < 90) {
             	                	balance = bet1 * 2 + balance;
             	                	System.out.println("You doubled your bet! Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland >= 50 && spinland < 75) {
             	                	balance = bet1 * 1 + balance;
             	                	System.out.println("Well, at least you made your money back.  Your new balance is $" + balance);
             	                }
             	                
             	                if (spinland < 50) {
             	                	balance = bet1 * 0 + balance;
             	                	System.out.println("Oops, better luck next time!  Your new balance is $" + balance);
             	                }
             	         System.out.println("Would you like to spin again or rebid? s/b?");
             	         Scanner second = new Scanner(System.in);
             	         char second1;
             	         second1 = second.findWithinHorizon("." , 0).charAt(0);
             	         
             	         if (second1 == 's' || second1 == 'S') {
             	        	 SlotInteract(balance, bet1);
             	         }
             	         
             	         if (second1 == 'b' || second1 == 'B') {
             	        	 SlotPlay();
             	         }
                     }
             
             
             if (answer2 == 'b') {
             	SlotPlay();
             }
         }
     	    
     	if (balance < bet1) {
     		System.out.println("You do not have enough money for that bet, please bet again.");
     		SlotPlay();
     	}
     	
    }
    }
    I have cleaned up the code a bit and tried using the boolean flags but am not quite sure how to use them with this code. I am also not sure about how to use the do-while loop with this code.
    If I could have a little help with that it would be great! Sorry for my easy questions but I am brand new at this :).

  8. #8
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Skipping code on second run through?

    For the do-while loop, something like the following would be applicable:

    Java Code:
    do
    {
    ask user how much they want to bet.
    ask user how many lines they want to play.
    balance = SlotInter()
    ask user if they want to play again.
    }
    while(user wants to play)
    This requires SlotInter() to return a value back to the calling method but eliminates the need for Slotinteract() all together.
    The SlotInter method would also need some additional work to removing the calls to SlotInteract() and SlotPlay(). These would no longer be required.

    Regards.

  9. #9
    Qwertyness_ is offline Member
    Join Date
    Mar 2013
    Location
    Hermon, Maine USA
    Posts
    7
    Rep Power
    0

    Default Re: Skipping code on second run through?

    I'm sorry for the delay but I have been short on time. I have managed to solve the original problem as well as add the do-while loop to the code instead of the if infustructure. Here
    is the new code:

    Java Code:
    import java.util.Scanner;
    import java.util.Random;
    
    public class SlotMachine {
    	public static void main(String[] args) {
    		boolean Run = false;
    		int balancedefine = 10;
    		System.out.println("Would you like to play SlotSo? Y/N?");
    		char answer1;
    		Scanner answer = new Scanner(System.in);
    		answer1 = answer.findWithinHorizon("." , 0).charAt(0);
    		if (answer1 == 'Y' || answer1 == 'y'){
    			SlotPlay(Run, balancedefine);
    		}
    
            if (answer1 == 'N' || answer1 == 'n') {
            	System.out.println("Thanks for playing SlotSo! Goodbye.");
            }
        }
            
        public static void SlotPlay(boolean Run, int balancedefine) {
            Scanner spinan = new Scanner(System.in);
            char spinans = 's';
        	do {
        		System.out.println("Your balance is $" + balancedefine);
            	int balance = balancedefine;
            	if (Run = false) {
            		balance = 10;
            	}
            	System.out.println("Would you like to bet $5, $10, $20, or $50?");
            			
            			Scanner betent = new Scanner(System.in);
            			int bet = betent.nextInt();
                System.out.println("Would you like to play 1, 2, 4, or 8 lines?");
                    Scanner line = new Scanner(System.in);    
                    int lines = line.nextInt();
                    
                    int fullbet = bet * lines;
                    SlotInter(fullbet, balance, spinans, spinan);
            }
        	while (spinans == 's' || spinans == 'S');
            
        }
        
        public static void SlotInter(int fullbet, int balance, char spinans, Scanner spinan) {  
        if (fullbet <= balance) {
            System.out.println("You have bet a total of $" + fullbet);
            System.out.println("Continue? Y/N?");
            Scanner answer = new Scanner(System.in);
            char answer1 = answer.findWithinHorizon("." ,  0).charAt(0);
            if (answer1 == 'y' || answer1 == 'Y') {
                if (spinans == 's') {
                	balance = balance - fullbet;
        	        Random spinner = new Random();
        	        int spinland;
        	            spinland = spinner.nextInt(100);
        	                if (spinland >= 95) {
        	        	        balance = fullbet * 10 + balance;
        	        	        System.out.println("Jackpot!!!!!!!. Your new balance is $" + balance);
        	                }
        	                
        	                if (spinland >= 90 && spinland < 95) {
        	                	balance = fullbet * 5 + balance;
        	                	System.out.println("Wow, thats a lot of dough! Your new balance is $" + balance);
        	                }
        	                
        	                if (spinland >= 75 && spinland < 90) {
        	                	balance = fullbet * 2 + balance;
        	                	System.out.println("You doubled your bet! Your new balance is $" + balance);
        	                }
        	                
        	                if (spinland >= 50 && spinland < 75) {
        	                	balance = fullbet * 1 + balance;
        	                	System.out.println("Well, at least you made your money back.  Your new balance is $" + balance);
        	                }
        	                
        	                if (spinland < 50) {
        	                	balance = fullbet * 0 + balance;
        	                	System.out.println("Oops, better luck next time!  Your new balance is $" + balance);
        	                }
        	         System.out.println("Would you like to spin again or rebid? s/b?");
        	         spinans = spinan.findWithinHorizon("." , 0).charAt(0);
        	         if (spinans == 's' || spinans == 'S') {
        	        	 SlotInter(fullbet, balance, spinans, spinan);
        	         }
        	         else {
        	        	int balancedefine = balance;
        	            RunCheck(balance, balancedefine); 
        	         }
                    }
                }
            }
        
            else {
            	int balancedefine = balance;
                RunCheck(balance, balancedefine); 
            }
        }
        
        public static void RunCheck(int balance, int balancedefine) {
        	boolean Run;
        	if (balance < 10) {
        		Run = false;
        		SlotPlay(Run, balancedefine);
        	}
        	
        	if (balance >= 10) {
        		Run = true;
        		SlotPlay(Run, balancedefine);
        	}
        }
    }
    If you see anything else that could be better please do not hesitate to share!

    Thanks for all the help,
    Qwertyness_

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Skipping code on second run through?

    Quote Originally Posted by Qwertyness_ View Post
    If you see anything else that could be better please do not hesitate to share!
    Method and variable names should start with a lowercase letter. *
    Indents should be consistent (lines 32-39; lines 84 and 87-88) *
    Logical error at line 27. And that's why you should never write code that tries to compare a boolean to true of false.
    Verbose code in lines 101 to 110 which can be replaced by a single line, making the method redundant.

    db

    * Code Conventions for the Java Programming Language: Contents
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Skipping code on second run through?

    From top to bottom.

    • What is 'Run' defined on line 6? Its passed into SlotPlay() but never changes state so line 28 is always executed (assuming the if statement is corrected).
    • SlotPlay() creates three scanners. You could create a single global scanner an reuse that instead.
      (This is also applicable to the scanner defined on line 10).
    • 'spinans' defined on line 23 never changes value creating an infinate loop between lines 24 to 41.
    • The signature for SlotInter() is excessive and this method does not need to call SlotInter(). Instead, as metioned in #8 you can return the outcome of the calculation.



    Regards.
    Last edited by Ronin; 03-09-2013 at 11:09 PM. Reason: Formatting list

  12. #12
    Qwertyness_ is offline Member
    Join Date
    Mar 2013
    Location
    Hermon, Maine USA
    Posts
    7
    Rep Power
    0

    Default Re: Skipping code on second run through?

    The variable Run defined on line 6 was my solution to the selective defining of the balance variable. I defined it twice because it wouldn't let me call SlotPlay from SlotMachine without the variable Run in the parenthasis. Run has an opportunity to change value on line 106. This if statement will eventually allow or disallow the running of line 28. The method SlotMachine is never able to rerun in the code so the value statement does not become a problem. I then used balancedefine which is equal to balance at the end of SlotInter as a way to avoid the same type of problem with the Run variable as the balance variable. The code seems to work except for one thing. The way the code is written, if balance ever gets below $10, it should be reset to 10. This isn't a problem because I don't want this to happen but I thought this would become an issue for me. Am I wrong about this?
    Last edited by Qwertyness_; 03-11-2013 at 05:06 AM. Reason: Understood question better

  13. #13
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: Skipping code on second run through?

    Quote Originally Posted by Ronin View Post
    Instead, as metioned in #8 you can return the outcome of the calculation.
    Returning values from methods would mean you would not need to call SlotInter() from inside itself. The only thing SlotInter() needs to do is perform the calculation and return the result. The recursive call back to SlotInter() should be handled by SlotPlay().

    Regards.

Similar Threads

  1. Scanner skipping every other line
    By Dex in forum New To Java
    Replies: 2
    Last Post: 08-14-2012, 09:32 AM
  2. Skipping an Integer
    By BrainMelt in forum New To Java
    Replies: 9
    Last Post: 03-30-2011, 04:54 AM
  3. Skipping Scanner
    By chari_autumn in forum New To Java
    Replies: 2
    Last Post: 01-04-2011, 06:29 AM
  4. Skipping links!!!
    By jvh in forum New To Java
    Replies: 2
    Last Post: 03-04-2010, 12:11 AM
  5. skipping input
    By windie_86 in forum New To Java
    Replies: 1
    Last Post: 02-12-2008, 07:09 PM

Posting Permissions

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