• March 6th, 2012, 10:37 PM
shrewbaca
Im creating a simple craps game, and I have to use a class to come up with random numbers for the game, but Im not sure how to use it. Here's the code for both my work, and the random number class provided, respectively.

import java.util.Scanner;
public class EvenOddCraps {

public static final int MIN_BET = 1;
public static final int MAX_BET = 31250;

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);

int bet, casinoBankTotal = 1000000;

System.out.println("Would you like to play even/odd craps (y/n)?");
String input;
input = keyboard.nextLine();
char charOne = input.toUpperCase().charAt(0);

if( charOne == 'Y' ){
System.out.println("How many chips would you like to bet?");

bet = keyboard.nextInt();
input= keyboard.nextLine();
if( bet >= MIN_BET && bet <= MAX_BET)

System.out.println("Bet on an even or odd roll (e/o)?");
String evenOdd;
evenOdd = keyboard.nextLine();
char charTwo = evenOdd.toUpperCase().charAt(0);

if (charTwo == 'E'){
RandomDie randomdieObject = new RandomDie();

}
}

}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.util.Random;

/************************************************** *********
* The RandomDie class contains methods for simulating
* a roll of fair, six-sided die numbered 1 - 6.
* This class is used for educational purposes only.
*
* @author Sal LaMarca
* @version 1.0, 02/16/2012
************************************************** *********/
public class RandomDie {

//The seed value for the random number generator
private static final long SEED = System.currentTimeMillis();
//Construct a new random number generator based on the seed
private static Random randomNumGenerator = new Random(SEED);
//Set the number of faces on the die
private static final int FACES_ON_DIE = 6;

/************************************************** *********
* Return a random integer of 1, 2, 3, 4, 5, or 6 simulating
* a roll of a fair, six-side die.
*
* @return Return a random integer of 1, 2, 3, 4, 5, or 6.
************************************************** *********/
public static int getRandomDieRoll(){
return (randomNumGenerator.nextInt(FACES_ON_DIE) + 1);
}

}
• March 7th, 2012, 04:50 AM
Mr.777