473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Question about my craps game program

Hi there I need to make a Craps game for my class. Here are the parameters for it.

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 heres my code I have been looking at it for 2 hours and i just cannot seem to find why it does not run heres the code

Expand|Select|Wrap|Line Numbers
  1. public class CrapsGame {
  2.     public static void main(String[]args)
  3.     {
  4.         final int GAMES = 10000;
  5.         int num1,num2,num3,win = 0,lose=0;
  6.         double prob;
  7.  
  8.         die die1 = new die();
  9.         die die2 = new die();
  10.  
  11.         for(int roll = 1; roll<= GAMES;roll++)
  12.         {
  13.             die1.roll();
  14.             die1.roll();
  15.             num1 = die1.getFaceValue()+ die2.getFaceValue();
  16.  
  17.             if (num1 == 7 || num1==11)
  18.                 {
  19.                 win++;
  20.                 }
  21.             else if (num1==2 || num1==3 || num1 == 12)
  22.                 {
  23.                 lose++;
  24.                 }
  25.             else {
  26.                 die1.roll();
  27.                 die2.roll();
  28.                 num2 = die1.getFaceValue() + die2.getFaceValue();
  29.                     while(num2!=num1 || num2!=7)
  30.                     {
  31.                         die1.roll();
  32.                         die2.roll();
  33.                         num3 = die1.getFaceValue() + die2.getFaceValue();
  34.                     }
  35.                     if (num3==num1)    
  36.                     {
  37.                         win++;
  38.                     }
  39.                     else if (num2==7)
  40.                     {
  41.                         lose++;
  42.                     }
  43.  
  44.  
  45.                 }
  46.  
  47.  
  48.  
  49.  
  50.         }
  51.         prob = (win/(win+lose));
  52.         if(prob>50)
  53.         {
  54.         System.out.println("The probability of you winning is more than the houses");
  55.         }
  56.         else if (prob <50)
  57.         {
  58.             System.out.println("The probability of you winning is less than the houses");
  59.         }
  60.         else
  61.         {
  62.             System.out.println("The probability of you winning is the same as the houses");
  63.         }
  64.     }
  65. }
also i have another class for roll and die and i know that there is no error there because i used it with another program. any help would be greatly appreciated.
Sep 17 '09 #1
1 8432
Frinavale
9,735 Expert Mod 8TB
Have you tried stepping through the application with a debugger tool to see what is going wrong?

If you don't have a tool to step through the application, have you tried to print out lines of text to the screen to see where the application stops?
Sep 21 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
1
by: nemesis | last post by:
help!!! IMy problem is that I don't know how to make the increase/decrease part work. The specification given to me by my teacher was: if the layer wins, double the wager (done!), and if loses ,...
73
by: JoeC | last post by:
I am writing a game and I am having a challenge with my combat function. All I want to do is find out how to group pieces that are in the same space. There are two sides and all the units that...
1
by: lblock | last post by:
i have this code that plays the game of craps, but i need to be able to take how much they brought and how much they want to bet. show the number on the dice and tell them it they won or lose and...
2
by: ar30067 | last post by:
The 36 possible outcomes of rolling two dice. 7.18 What does the following program do? 1 // Ex. 7.18: Ex07_18.cpp 2 // What does this program do? 3 #include <iostream>
2
by: mer000 | last post by:
Can you guys help me out? I'm trying to create a very simple game of craps but having some trouble. Below are the rules and requirements. Much appreciated! Given the following rules for the game...
3
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u...
18
by: Rhodge09 | last post by:
This is my script it works fine but it comes out on my webpage as just text how can i change this around and make it so if i like click a button a 2 different numbers come up almost like the 2 dice...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.