We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,654 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

I need help with my project

I have a project. the project is:
In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the dice in a craps round is called the "come out roll." A come out roll of 7 or 11 automatically wins, and a come out roll of 2, 3, or 12 automatically loses. 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 a 7 is rolled first, then the player loses.

Write a program that simulates a game of craps using these rules without human input. Instead of asking for a wager, the program should calculate whether 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, you or the house?

Note: To generate a random number X, where 0 <= X < 1, use X = Math.random();. For example, multiplying Math.random() by 6 and converting to an integer results in a random integer that is between 0 and 5.

And, I already have some, I just havd no idea how to do the next step...

import java.util.Random;

public class Project2 
{

    public static void main(String[] args) 
    {
        Random rand = new Random();

        int grt=10000;//game run times
        int dice3=0;
        for(int i=0; i<100; i++)
        {
           int dice1 = (int)((Math.random()*6)+ 1);
           int dice2 =  rand.nextInt(6)+1;
           dice3  = (dice1 + dice2);
        }

        if(dice3 == 2 || dice3 == 3 || dice3 == 12)
        {
             System.out.println("you lose");
        }
        else if(dice3 == 7 || dice3 == 11)
        {
             System.out.println("you win"); 
        }
        else
            {
             System.out.println("Your point is "+dice3);

            }
        }



}
3
Contributors
3
Replies
1 Day
Discussion Span
3 Months Ago
Last Updated
4
Views
kamil555
Newbie Poster
2 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Write a method that rolls two dice and returns the value. Then write a method that does a come out roll and returns a win, a loss, or a point. Then write a method that does an entire game: a come out roll and then repeated rolls until the result is determined and a win or a loss is returned. Then in your main you just need to call the game method 10,000 times.

It is almost always true of problems that they can be made easy by breaking them into small pieces.

bguild
Posting Whiz
327 posts since Oct 2012
Reputation Points: 166
Solved Threads: 73
Skill Endorsements: 7

thanks for your reply, actually I just stuck at the part of reroll the dice, see it equals to the point or 7, I really have no idea for doing that. can you give me some ideas how fix it please?

kamil555
Newbie Poster
2 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Generate two random numbers 1-6, add them together, test the result for ==7 or whatever else you need.

JamesCherrill
... trying to help
Moderator
8,497 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0687 seconds using 2.68MB