# Roulette Program

• 01-10-2006, 11:24 PM
CircuitConcepts
Roulette Program
I've been working on this program for a spot of fun lately. I'm not a super experienced coder with Java, but don't worry about dumbing things down. This program isn't very complex in itself, but for some reason it isn't doing what I want it to!

Code:

import java.io.*;
import java.util.Random;
import java.text.DecimalFormat;

public class Roulette
{
public static void main (String args[]) throws IOException
{
Random generator = new Random();
DecimalFormat dollarOutput = new DecimalFormat ("\$00.00");

char userInput;
char userInput2;
char betType;
char spinSuccess;
char successType;
char eOSuccessType;
int betNum;
int rouletteSpinNum;
double userMoney = 100.0;
double betAmount;

System.out.println("Welcome to Thomas' Casino of Luck!");
System.out.println("How about spin of Roulette?");

do{
System.out.print("\nType in 'y' to play, 'n' to quit or 'r' for the rules.\t");

if (userInput == 'y')
{
System.out.println("\nYou have\t\t\t\t" + dollarOutput.format(userMoney) + ".");
System.out.print("How much do you want to bet?\t\t");
if (betAmount > userMoney)
{
System.out.println("You can't bet what you don't have!");
}
else{
System.out.print("\nWould you like to bet on:\n\t'e' evens\n\t'o' odds\n\t'q' a quadrant\n\t's' for a specific number\t");

rouletteSpinNum = generator.nextInt(100) + 1;

if (rouletteSpinNum % 2 == 0)
eOSuccessType = 'e';
else
eOSuccessType = 'o';

if (rouletteSpinNum <=25)
else if (rouletteSpinNum <= 50)
else if (rouletteSpinNum <= 75)
else

System.out.println("");

if (betType == 's')
{
System.out.print ("\nWhat number would you like to bet on?\t");

if (betNum == rouletteSpinNum)
{
System.out.println("\nThe roulette wheel stopped on " + rouletteSpinNum + "\n");
userMoney = userMoney + (betAmount * 4.0);
System.out.println("You now have:\t" + dollarOutput.format(userMoney));
}
else
{
System.out.println("\nUnfortunately, the roulette wheel stopped on " + rouletteSpinNum);
System.out.println("You guessed " + betNum);
userMoney = userMoney - betAmount;
System.out.println("You now have:\t" + dollarOutput.format(userMoney));
System.out.println("\nBetter luck next time!\n");
}
}
else if (betType == 'e' || betType == 'o')
{
if (eOSuccessType == 'e')
{
System.out.println("\nThe roulette wheel stopped on " + rouletteSpinNum + "\n");
System.out.println("*******************************\nYou've just doubled your bet!\n*******************************\n");
userMoney = userMoney + (betAmount * 2.0);
System.out.println("You now have:\t" + dollarOutput.format(userMoney));
}
else if (eOSuccessType == 'o')
{
System.out.println("\nThe roulette wheel stopped on " + rouletteSpinNum + "\n");
System.out.println("*******************************\nYou've just doubled your bet!\n*******************************\n");
userMoney = userMoney + (betAmount * 2.0);
System.out.println("You now have:\t" + dollarOutput.format(userMoney));
}

else
{
System.out.println("\nUnfortunately the Roulette wheel came to a stop on " + rouletteSpinNum);
userMoney = userMoney - betAmount;
System.out.println("You now have:\t" + dollarOutput.format(userMoney));
System.out.println("\nBetter luck next time!\n");
}
}
}
}
else if (userInput == 'r')
{
do{
System.out.println("\n******************************************************************************");
System.out.println("The Rules of Roulette!");
System.out.println("1.) You can bet any increment of money you have.");
System.out.println("2.) If you lose your bet you lose the money.");
System.out.println("3.) You can bet on any whole number from 1 to 100 (inclusive).");
System.out.println("4.) If you bet your money on an even or odd and win your bet is doubled.");
System.out.println("5.) If you bet your money on a quadrant and win your bet is tripled.");
System.out.println("5.) If you bet your money on a specific number and win, the bet is quadrupled.");
System.out.println("******************************************************************************");
System.out.print("\nHit 'm' to read more, or 'd' if you're done.\t\t");

if (userInput2 == 'm')
{
System.out.println("\nHere is a sample round:");
System.out.println("\tYou opt to bet \$20.00.");
System.out.println("\tYou then opt to bet on Even numbers.");
System.out.println("\tWhen the Rouette Wheel finishes it lands on a 44.");
System.out.println("\tYou've just doubled your bet and made \$40.00.");
System.out.println("If you're still confused just play a few rounds to understand more.\n");

userInput2 = 'd';
}
else if (userInput2 == 'd')
System.out.println("\nBack to the beginning!");
else
System.out.println("\nThat's not a valid input, try again!");
}while (userInput2 != 'd');
}
else if (userInput == 'n')
System.out.println("\nThanks for playing!");
else
{
System.out.println("\nI'm sorry, but that's not a valid option, try again!\n");
}
}while (userInput != 'n');

System.out.println("You started with:\t\t\t\$100.00");
System.out.println("You finished with:\t\t\t" + dollarOutput.format(userMoney));
System.out.println("You made, in total:\t\t\t" + dollarOutput.format((userMoney - 100)) + "\n");
}
}

It's a simple game of roulette, though be warned as its under construction, quadrants don't function. Only snippets of the code for it are there.

Here's my problem: If you opt to bet on evens or odds you always win. Even if it rolls a 97 it will happily tell you, you got a 97 and bet on evens and then give you your money back!

I've become clueless, staring at the code so much gets to meh.

Thanks!
• 01-11-2006, 12:00 AM
destin
Quote:

Code:

else if (betType == 'e' || betType == 'o') {
if (eOSuccessType == 'e') {
System.out.println("\nThe roulette wheel stopped on " +
rouletteSpinNum + "\n");
System.out.println("*******************************\n" +
"You've just doubled your bet!" +
"\n*******************************\n");
userMoney = userMoney + (betAmount * 2.0);
System.out.println("You now have:\t" +
dollarOutput.format(userMoney));
} else if (eOSuccessType == 'o') {
System.out.println("\nThe roulette wheel stopped on " +
rouletteSpinNum + "\n");
System.out.println("*******************************\n" +
"You've just doubled your bet!" +
"\n*******************************\n");
userMoney = userMoney + (betAmount * 2.0);
System.out.println("You now have:\t" +
dollarOutput.format(userMoney));
}
//...

You're saying that if they enter 'e' or 'o', they win, because if they do enter 'e' or 'o', eOSuccessType will be either 'e' or 'o', and it says right there in your code to tell them they win if that is the case. Change that block of code to this and it should work.
Code:

if (betType == eOSuccessType) {
System.out.println("\nThe roulette wheel stopped on " +
rouletteSpinNum + "\n");
System.out.println("*******************************\n" +
"You've just doubled your bet!" +
"\n*******************************\n");
userMoney = userMoney + (betAmount * 2.0);
System.out.println("You now have:\t" +
dollarOutput.format(userMoney));
}

• 01-11-2006, 12:23 AM
CircuitConcepts
The issue aren't words saying they won, it's the actual variable. It still gives them the money.

I fixed the solution by getting rid of the pipes and just spreading it out over a few ifs.
• 01-11-2006, 07:16 AM
destin
If you made the change that i suggested, it would have worked. You were
not only displaying the words put changing the varialbe there as well.