Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I need help with my project...

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Location
    Bremerton, WA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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...
    there is my code:
    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);
     
    		    }
    		}
     
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help with my project...

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    What steps have you done?
    What is the next step you are working on?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Location
    Bremerton, WA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help with my project...

    I'm stuck at the part of reroll the dice, I have no idea how to let it reroll again, and get a number see it equal to teh point or 7. that's it , thanks for your help.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I need help with my project...

    how to let it reroll again
    sounds like you need a loop.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. need help on my project..
    By jikoy in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 21st, 2012, 11:57 AM
  2. project
    By rafishaik999 in forum The Cafe
    Replies: 4
    Last Post: December 22nd, 2010, 12:45 PM
  3. Project - Please Help
    By toxikbuni in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 09:58 AM
  4. Can anyone help me on my project?
    By alesana514 in forum Paid Java Projects
    Replies: 1
    Last Post: December 16th, 2009, 09:24 AM
  5. Need Help With Project
    By jstew132 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 11th, 2009, 07:15 PM

Tags for this Thread