Post a New Question

Computer Science Java

posted by on .

I have to write program for a dice game and use a boolean variable in the application class of the dice game that equals true when snake eyes, doubles, and box cars have been meet. I am having a little trouble doing that in my application class so I was wondering if somebody can help me out. This is how my application class looks now:

package classes;

public class DiceGameApp {

public static void main (String [] args) {

DiceGame dice = new DiceGame ();

for (int rollCount = 0; rollCount < 10; rollCount ++) {


System.out.println("\nYou rolled a " + dice.getDieone()+ " for dice one and a " +dice.getDietwo()+ " for dice two.");

if(dice.getDieone()== 1 && dice.getDietwo()== 1){

System.out.println ("\nYou have rolled snake eyes.");
if (dice.getDieone()== 6 && dice.getDietwo()== 6)

System.out.println("\nYou have rolled boxcars.");


System.out.println("\nYou have rolled doubles.");



  • Computer Science Java - ,

    A Boolean variable is a variable, like an int or a string, but whose value is either "true" or "false".

    Try this little lump of code, and vary d1 and d2 values, to see the effect:

    int d1 = 1
    int d2 = 1

    boolean snakeeyes;
    boolean doubles;
    boolean boxcars;

    snakeeyes = (d1 + d2 == 2);
    doubles = (d1 == d2);
    boxcars = (d1 + d2 = 12);

    System.out.println("Is this snake-eyes?");

    // and you can also use it in a logical statement
    System.out.println("Is this bpxcars?");
    if (boxcars) System.out.println("Yes");

    and so on.

    It's not clear from your description whether your project calls for one boolean condition for each condition or one for any of them, but I hope this example will illustrate the general method.

Answer This Question

First Name:
School Subject:

Related Questions

More Related Questions

Post a New Question