I can't get this program to process the numberPayoff portion which pays off 36 * bet. It seems yourNumber is not being compared to ballPosition correctly.
import java.io.*;
import java.util.*;
//*************************************************************
//Class Roulette contains the main driver for a roulette game
//*************************************************************
class Roulette {
//========================================================
// Contains the main processing loop for the roulette game
//========================================================
publicstaticvoid main (String[] args) throws IOException{
Player player = new Player (100);
boolean done = false;
System.out.println ("Cash available: " + player.cash());
System.out.println();
while (!done) {
player.makeBet();
System.out.println ("Cash available: " + player.cash());
done = !player.spinAgain();
System.out.println();
}
}//method main
} //class Roulette
//*****************************************************************
// Class Player represents one roulette player.
//*****************************************************************
class Player {
publicstaticint bet,ballPosition,money;
privatestatic BufferedReader stdin;
privatestaticint betType;
publicint yourSpin;
privateint totalpay;
publicstaticint totalwinnings, winnings, yourNumber;
//=============================================================
// The player constructor sets up the initial available cash.
//=============================================================
public Player (int initialMoney) {
money = initialMoney;
stdin = new BufferedReader (new InputStreamReader(System.in));
}//constructor Player
//================================================================
// Returns this player's current available cash.
//================================================================
publicint cash() {
return money;
} //method cash
//==============================================================
// Prompts the user and reads betting information.
//==============================================================
publicvoid makeBet() throws IOException{
System.out.print ("How much to bet: ");
bet = Integer.parseInt (stdin.readLine());
money = money - bet;
if (money == 0)
System.out.println ("Betting it all!");
betType = Wheel.betOptions( new BufferedReader( new
InputStreamReader(System.in)));
if (betType == 3){
System.out.println ("Pick a number from 1 to 37.");
yourNumber = Integer.parseInt (stdin.readLine());}
yourSpin = Wheel.spin();
totalpay = Player.payment();
}//method makeBet
publicstaticint payment(){
totalwinnings = ((Wheel.numberPayoff(bet,betType,ballPosition,yourNumber,winnings)) + (Wheel.redPayoff(bet,betType,ballPosition,winnings))+ (Wheel.blackPayoff(bet,betType,ballPosition,winnings)));
System.out.println ("Total payoff is " + totalwinnings);
System.out.println ();
money = money + totalwinnings;
return money;
} //method payment
//==============================================================
// Determines if the player wants to spin wheel again.
//==============================================================
publicboolean spinAgain() throws IOException{
String answer;
System.out.print ("Spin again [y/n]? ");
answer = stdin.readLine();
return (answer.equals ("y") || answer.equals ("Y"));
} //method spin_again
} //class Player
//****************************************************************
// Class Wheel represents a roulette wheel and its operations. Its
// data and methods are static because there is only one wheel.
//***************************************************************
class Wheel {
privatefinalstaticint RED = 1;
privatefinalstaticint BLACK = 2;
privatefinalstaticint POSITIONS = 37;
privatestaticint ballPosition;
privatestaticint color;
publicstaticint spin()
{
int ballPosition = (int) (Math.random() * (POSITIONS - 1));
if (ballPosition%2 == 0) {
color = RED;
System.out.println ("Color is RED");
System.out.println ("Spin is: " + ballPosition);}
else {
color = BLACK;
System.out.println ("Color is BLACK");
System.out.println ("Spin is: " + ballPosition);}
return ballPosition;
}
publicstaticint numberPayoff ( int bet, int betType, int ballPosition, int yourNumber, int winnings){
if (betType == 3 && ballPosition == yourNumber)
winnings = bet * 36 + bet;
return winnings;
}
publicstaticint redPayoff (int bet, int betType, int ballPosition,int winnings){
if (betType == 1 && color == 1)
winnings = bet * 2 + bet;
return winnings;
}
publicstaticint blackPayoff (int bet, int betType, int ballPosition,int winnings){
if (betType == 2 && color == 2)
winnings = bet * 2 + bet;
return winnings;
}
//==============================================================
// Presents betting options and reads player choice.
//=============================================================
publicstaticint betOptions (BufferedReader stdin)
throws IOException{
System.out.println ("1. Bet on red");
System.out.println ("2. Bet on black");
System.out.println ("3. Bet on a particular number");
System.out.print ("Your choice? ");
return Integer.parseInt (stdin.readLine());
}
} // class Wheel