954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help

I'm having a hard time figuring out what i'm doing wrong. Can someone help ? this is the question :

In the game of Craps, a "Pass Line" bet proceeds as follows. Using two six-sided dice, the first roll of the dice in a craps round is called the "Come Out Roll." The bet immediately wins when the come out roll is 7 or 11, and loses when the come out roll is 2, 3, or 12. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes "the point." The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If the player rolls a 7 first, then the player loses.

Write a program that plays the game of Craps using the rules stated above so that it simulates a game without human input. Instead of asking for a wager, the program should just calculate if the player would win or lose. The program should simulate rolling the two dice and calculate the sum. Add a loop so that the program plays 10,000 games. Add counters that count how many times the player wins, and how many times the player loses. At the end of the 10,000 games, compute the probability of winning, i.e. Wins / (Wins + Losses) and output this value. Over the long run, who is going to win the most games of Craps, you or the house?


This is what i have:

public class Craps1
 {
     public static void main(String[]args)
     {
         final int GAMES = 10000;
         int num1,num2,num3,win = 0,lose=0;
         double prob;

        die die1 = new die();
        die die2 = new die();

        for(int roll = 1; roll<= GAMES;roll++)
         {
             die1.roll();
             die1.roll();
             num1 = die1.getFaceValue()+ die2.getFaceValue();

             if (num1 == 7 || num1==11)
                 {
                 win++;
                 }
             else if (num1==2 || num1==3 || num1 == 12)
                 {
                 lose++;
                 }
             else {
                 die1.roll();
                 die2.roll();
                 num2 = die1.getFaceValue() + die2.getFaceValue();
                     while(num2!=num1 || num2!=7)
                     {
                         die1.roll();
                         die2.roll();
                         num3 = die1.getFaceValue() + die2.getFaceValue();
                     }
                     if (num3==num1)
                     {
                         win++;
                     }
                     else if (num2==7)
                     {
                         lose++;
                     }


                 }




         }
         prob = (win/(win+lose));
         if(prob>50)
         {
         System.out.println("The probability of you winning is more than the houses");
         }
         else if (prob <50)
         {
             System.out.println("The probability of you winning is less than the houses");
         }
         else
         {
             System.out.println("The probability of you winning is the same as the houses");
         }
     }
 }
kandyhyatt
Newbie Poster
11 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

You say you are doing something wrong - but what symptoms do you have - a compile error, and exception being thrown, program produces the wrong results etc?
Without an exact description of the problem you are unlikely to find the right solution.
But in the meantime, where is the class die?

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

I'm having a hard time figuring out what i'm doing wrong. Can someone help ? this is the question :

In the game of Craps, a "Pass Line" bet proceeds as follows. Using two six-sided dice, the first roll of the dice in a craps round is called the "Come Out Roll." The bet immediately wins when the come out roll is 7 or 11, and loses when the come out roll is 2, 3, or 12. If 4, 5, 6, 8, 9, or 10 is rolled on the come out roll, that number becomes "the point." The player keeps rolling the dice until either 7 or the point is rolled. If the point is rolled first, then the player wins the bet. If the player rolls a 7 first, then the player loses.

Write a program that plays the game of Craps using the rules stated above so that it simulates a game without human input. Instead of asking for a wager, the program should just calculate if the player would win or lose. The program should simulate rolling the two dice and calculate the sum. Add a loop so that the program plays 10,000 games. Add counters that count how many times the player wins, and how many times the player loses. At the end of the 10,000 games, compute the probability of winning, i.e. Wins / (Wins + Losses) and output this value. Over the long run, who is going to win the most games of Craps, you or the house?

This is what i have:

public class Craps1
 {
     public static void main(String[]args)
     {
         final int GAMES = 10000;
         int num1,num2,num3,win = 0,lose=0;
         double prob;

        die die1 = new die();
        die die2 = new die();

        for(int roll = 1; roll<= GAMES;roll++)
         {
             die1.roll();
             die1.roll();
             num1 = die1.getFaceValue()+ die2.getFaceValue();

             if (num1 == 7 || num1==11)
                 {
                 win++;
                 }
             else if (num1==2 || num1==3 || num1 == 12)
                 {
                 lose++;
                 }
             else {
                 die1.roll();
                 die2.roll();
                 num2 = die1.getFaceValue() + die2.getFaceValue();
                     while(num2!=num1 || num2!=7)
                     {
                         die1.roll();
                         die2.roll();
                         num3 = die1.getFaceValue() + die2.getFaceValue();
                     }
                     if (num3==num1)
                     {
                         win++;
                     }
                     else if (num2==7)
                     {
                         lose++;
                     }


                 }




         }
         prob = (win/(win+lose));
         if(prob>50)
         {
         System.out.println("The probability of you winning is more than the houses");
         }
         else if (prob <50)
         {
             System.out.println("The probability of you winning is less than the houses");
         }
         else
         {
             System.out.println("The probability of you winning is the same as the houses");
         }
     }
 }


I am getting back numerous errors .. Where do i include the class die

kandyhyatt
Newbie Poster
11 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
 

What errors specifically? "Numerous errors" doesn't really mean much to someone who can't see them, and since you didn't post the "die" class no one else can compile and run this.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You