Hey, I've been recently coding a java program for the High Low dice game. I'm absolutely sure of my logic in that I know what i have to do, it's just executing it. Methods and how to call them are my main crux. I'm stumped at the moment, and I'm aware that the experienced coders will probably cringe at the amateur mistakes I've made, but you gotta learn from those. All that happens with this code is it constantly finds whatever is put in as invalid. But you already knew that. :)
/**
* High-Low is a dice game played with two dice against a banker.
*
* Players are identified by a name and have an initial amount of money. Before the game
* starts, players place their bets on oNE of three outcomes of the total of the two dice.
*
* The possible outcomes are:
* High if the total: 8,9,10,11 or 12
* Low if the total: 2,3,4,5, or 6
* Seven if the total is 7.
*
* The dice are then rolled. The payoffs for a wining bet of High or Low is 1:1. The payoff
* for a bet of seven is 4:1.
*/
import java.util.*;
public class diceGame
{
static int rollOne;
static int rollTwo;
static int odds;
static int total;
static String bet;
public static int rollOne(int rollOne, int rollTwo)
{
rollOne = (int)(Math.random()*6+1);
rollTwo = (int)(Math.random()*6+1);
return total = rollOne + rollTwo;
}
public static void main(String[] args)
{
int rollTotal = 0;
Scanner in = new Scanner(System.in);
System.out.print("Please enter your bet ('high', 'low' or 'seven'): ");
String bet = in.nextLine();
if (bet == "high")
{
rollTotal = total;
}
else if (bet == "low")
{
}
else if (bet == "seven")
{
}
else
System.out.println("That is not a valid bet (please enter 'high', 'low' or 'seven'):");
}
}
Here's my pseudocode logic that I've written out:
roll1 = CALL roll die
roll2 = CALL roll die
total = roll1 + roll2
IF total > 7 and guess is high
OR total < 7 and guess is low
Display “Player wins”
Set odds to 1
ELSE IF total = 7 and guess is seven
Display “Player wins”
Set odds to 4
ELSE
Display “Player loses”
Set odds to 0
Return odds]
Help where to go next appreciated :)