Hello guys..
I want to write a small Hi Lo Betting Dice program that satisfies these conditions :
A player places a bet on whether the sum of two dice will come up High (totalling 8 or higher), Low (totalling 6 or less) or Sevens (totalling exactly 7). If the player wins, he receives a payout based on the schedule given in the table below:
Choice Payout
High 1 x Wager
Low 1 x Wager
Sevens 4 x Wager
The player will start with $100 for wagering. If the player chooses to wager $0 or if he runs out of money, the program should end. Otherwise it should ask him whether he's wagering on High, Low or Sevens, display the results of the die rolls, and update his money total accordingly.
some sample output:
You have 100 dollars.
Enter an amount to bet (0 to quit): 50
High, low or sevens (H/L/S): H
Die 1 rolls: 1
Die 2 rolls: 5
Total of two dice is: 6
You lost!
You have 50 dollars.
Enter an amount to bet (0 to quit): 25
High, low or sevens (H/L/S): L
Die 1 rolls: 6
Die 2 rolls: 2
Total of two dice is: 8
You lost!
You have 25 dollars.
Enter an amount to bet (0 to quit): 12
High, low or sevens (H/L/S): H
Die 1 rolls: 2
Die 2 rolls: 6
Total of two dice is: 8
You won 12 dollars!
I have written some code but now i am stuck at the logic maybe and i don't know how should i go ahead with it.. I don't want the exact codes but i want direction as to how should i go about doing my business.. Any help will be highly appreciated..
(I am just starting at Java and i found this exercise online and so i want to try to do it myself)
package com.peg.hilodice; import java.util.Scanner; public class DiceGame { public static void main(String[] args) { // TODO Auto-generated method stub int money = 100; int bet; System.out.println("Hello! Welcome to Hi-Lo Dice Betting"); System.out.println("You have $" + money + "." ); System.out.println("How much $ would you like to bet ?"); Scanner sc = new Scanner(System.in); bet = sc.nextInt(); if (bet > money ) { System.out.println("You don't have enough funds"); }else if (bet < money) { System.out.println("Choose your guess: H for Hi, L for Lo and S for Seven"); Scanner scr = new Scanner(System.in); String guess = scr.nextLine(); System.out.println("You chose : " + guess); int diceOne = (int)(Math.random()*6) + 1; System.out.println("Dice one is : " + diceOne); int diceTwo = (int)(Math.random()*6) + 1; System.out.println("Dice two is : " + diceTwo); int diceTotal = diceOne + diceTwo; System.out.println("Your Total : " + diceTotal); if (diceTotal > 7) { System.out.println("It's a HI"); }else if (diceTotal <7) { System.out.println("It's a LO"); }else { System.out.println("It's SEVEN"); } } } }