Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-30-2008, 08:34 PM
Member
 
Join Date: Jun 2008
Posts: 1
pat8 is on a distinguished road
java help please- two sided dice
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?

please help me in this project

public class Kharel_Ch3_2 {

public static int NUM_GAMES = 10000;

public static void main(String[] args) {

int numWins = 0;
int numLosses = 0;

int x;
int y;

x = (int)(Math.random()*6) + 1;
y = (int)(Math.random()*6) + 1;

System.out.println("The roll of first Dice is " + x);
System.out.println("The roll of Second Dice is " + y);

int roll = (x + y);

System.out.println("The sum of two dice is " + (roll));


int point = (4 & 5 & 6 & 8 & 9 & 10);

for (int i = 1; i<=10000; i++)
if (roll == 7 || roll == 11)
{
System.out.println("You win!");

numWins = numWins +1;
}

else if (roll==2 || roll==3 || roll==12)
{
System.out.println("You Lose!");

numLosses = numLosses + 1;
}

else
{
System.out.println("Roll Dice again!!!");

x = (int)(Math.random()*6) + 1;
y = (int)(Math.random()*6) + 1;

roll = (x + y);
}

{

if (roll == point);
{

}
while (roll !=7 || roll !=point)


x=(int)(Math.random()*6);
y=(int)(Math.random()*6);

roll = (x + y);

int sum = roll;

}
{

if (roll== point)
numWins = numWins+1;

else numLosses=numLosses+1;

}
// Output probability of winning
System.out.println("In the simulation, we won " + numWins +
" times and lost " + numLosses + " times, ");
System.out.println("for a probability of " +
(double)(numWins)/(double)(numWins + numLosses));
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-01-2008, 01:28 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Formatted but not compiled.
Code:
public class Kharel_Ch3_2 { public static int NUM_GAMES = 10000; public static void main(String[] args) { int numWins = 0; int numLosses = 0; int x = (int)(Math.random()*6) + 1; int y = (int)(Math.random()*6) + 1; System.out.println("The roll of first Dice is " + x); System.out.println("The roll of Second Dice is " + y); int roll = (x + y); System.out.println("The sum of two dice is " + (roll)); int point = (4 & 5 & 6 & 8 & 9 & 10); for (int i = 1; i<=10000; i++) if (roll == 7 || roll == 11) { System.out.println("You win!"); numWins = numWins +1; } else if (roll==2 || roll==3 || roll==12) { System.out.println("You Lose!"); numLosses = numLosses + 1; } else { System.out.println("Roll Dice again!!!"); int thePoint = roll; do { x = (int)(Math.random()*6) + 1; y = (int)(Math.random()*6) + 1; roll = (x + y); if (roll == thePoint) numWins++; else if(roll == 7) numLoses++; } while (roll != 7 || roll != thePoint); } } // Output probability of winning System.out.println("In the simulation, we won " + numWins + " times and lost " + numLosses + " times, "); System.out.println("for a probability of " + (double)(numWins)/(double)(numWins + numLosses)); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-01-2008, 01:41 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,225
Norm is on a distinguished road
Sorry, I missed what your problem with writing the program was.
Could you please explain.
Are you able to compile your program? If not copy the errors and post them here.
Same for execution time errors.
If you are not getting the correct results, show what you are getting and explain why that is wrong and show what you would like the output to be.
Or are you looking for someone to do your homework for you?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-01-2008, 04:25 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 1,289
Fubarable is on a distinguished road
Quote:
Sorry, I missed what your problem with writing the program was.
Could you please explain.
Don't bother. He's cross-posted this in the Sun forums, and in god-knows what other forum.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Roll 2-Dice "Pig" Game Help King8654 AWT / Swing 7 04-07-2008 08:58 PM
Defective code for dice, help please? byron New To Java 10 04-01-2008 08:22 AM
Help debugging a dice game Windoze New To Java 7 11-22-2007 03:01 AM
help debugging a dice game Windoze Advanced Java 0 11-17-2007 12:28 AM


All times are GMT +3. The time now is 12:46 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org