Kinda new to Java here. I want to detect the words "winner" or "loser" in my print return statements belonging to makeBet() in my RouletteGame class from playRound() in class RouletteTester. I'm trying to create boolean statements based on which word was detected. Is there any way to do this?
Here is my method from the class RouletteGame:
public String makeBet(int betAmount, String betType) {
String result = this.wheel.spin();
if ((betAmount > 0) || (betAmount < credits)) {
// Determines results for color bets
if (betType == "red" || betType == "black") {
this.wheel.getColor(result);
if (this.wheel.getColor(result) == "red") {
this.credits += betAmount;
return this.wheel.getColor(result) + "- winner";
}
else if (this.wheel.getColor(result) != "red") {
this.credits -= betAmount;
return this.wheel.getColor(result) + " - loser";
}
if (this.wheel.getColor(result) == "black") {
this.credits -= betAmount;
return this.wheel.getColor(result) + " - winner";
}
else if (this.wheel.getColor(result) != "black") {
this.credits -= betAmount;
return this.wheel.getColor(result) + " - loser";
}
}
// Determines results for parity bets
if (betType == "even" || betType == "odd") {
this.wheel.getParity(result);
if (this.wheel.getParity(result) == "even") {
this.credits += betAmount;
return this.wheel.getParity(result) + "- winner";
}
else if (this.wheel.getParity(result) != "even") {
this.credits -= betAmount;
return this.wheel.getParity(result) + " - loser";
}
if (this.wheel.getParity(result) == "odd") {
this.credits -= betAmount;
return this.wheel.getParity(result) + " - winner";
}
else if (this.wheel.getParity(result) != "odd") {
this.credits -= betAmount;
return this.wheel.getParity(result) + " - loser";
}
}
// Determines results for a bet on a certain number
int intResult = Integer.parseInt(result);
int intBet = Integer.parseInt(betType);
if (intBet == intResult) {
this.credits += 35*betAmount;
return result + " - winner";
}
else {
this.credits -= betAmount;
return result + " - loser";
}
}
else if (betAmount < 0) {
this.credits = 0;
}
else if (betAmount > credits) {
betAmount = this.credits;
}
return "Please spin again";
And I am trying to reference my return statements in makeBet() from playRound() in class RouletteTester (below). After a loss (i.e., if the string return statement in makeBet() contains "loser"), I would like to double the bet amount, and after a win (if it contains the word, "winner"), I would like to go back to the original bet amount.
public static int playRound(String betType, int betAmount) {
int startAmount = betAmount * RouletteTester.SPINS_PER_ROUND;
RouletteGame game = new RouletteGame();
game.addCredits(startAmount);
for (int roundNum = 0; roundNum < RouletteTester.SPINS_PER_ROUND; roundNum++) {
if (game.checkCredits() > 0) {
int nextBet = Math.min(betAmount, game.checkCredits());
game.makeBet(nextBet, betType);
}
}
return game.checkCredits() - startAmount;