• Post Reply Bookmark Topic Watch Topic
  • New Topic

Roulette Game  RSS feed

 
Desiree Bernard
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello,

I am to write a Roulette game where numbers 18 and under lose the bet (bets are up to 3 dollars). The game ends when the player either loses or wins 1,000 dollars:

I have worked on the code below but it seems that my compiler doesn't like the methods. Can anyone point me in the right direction as to where the problem is?

Regards,

_________________________________________________


public class Roulette extends ConsoleProgram {
    public void run () {
       
        int money = 10;
        int spin = 0;      
        int bet = readInt ("Enter bet:");
       
        while (money > 0 && money <= 1000) {           
        spinWheel();
        winLose(spin, money, bet);  
           
        print ("bet $" + bet);
        print (", spin" + spin);
        print ( ", money = $" + money);
           
        bet = readInt("bet: ");
        }
    }
}
       
        private int spinWheel ()   {          
        int spin = RandomGenerator.getInstance().nextInt(1,50);
            return spin;
        }
       
        private int winLose (int spin, int money, int bet) {          
        if (spin <= 18) {
        int win = bet;
        money += win;
       
           
        } else {
        int loss = bet;
        money -= loss;
        }
            return money;
        }   
           
 
Carey Brown
Bartender
Posts: 3001
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your methods return values that you're not doing anything with.
 
Carey Brown
Bartender
Posts: 3001
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Desiree Bernard wrote:I have worked on the code below but it seems that my compiler doesn't like the methods.

Please post the complete text of any error messages.
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also be sure to wrap all posted code in code tags.  Use the above Code button 
 
Knute Snortum
Sheriff
Posts: 4080
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To echo what Norm said, please UseCodeTags (that's a link).  It looks like you tried, but the code needs to go in between the opening and closing tags.  Also, you can use the Preview button, just to the left of the Submit button, to see if you've done everything correctly.

Here's what your code looks like in code tags:

When you've posted your complete code with the complete error message, I'm sure we can help you.  I have an idea what the problem is, but without seeing the import statements, I can't tell for sure.
 
Arco Brouwer
Ranch Hand
Posts: 44
2
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I see at the moment is that the methods spinWheel() and winLose() are declared outside the class body.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!