Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Annoying Error

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My game runs 1000 games of craps, displays the number of wins and losses, average chance to win and averge turns at the end and also number of time won and lost on each number of rolls.

1. It displays 0 for the first number I print, when it should be some very large number (ex 200 or 300).

2. The average chance of winning is not showing. I put in several different places but its wont show.

 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the average displays for me, it is the "Chance of winning" which doesn't display - you don't have a winpField.setText() anywhere.

another thing
for (int i=0; i < count.length; i++)
{
...
firstRoll = true;
}

perhaps this should be firstRoll = false;
 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, Im so stupid sometimes, thanks for pointing it out.

The problem with the 0 isnt fixed. Firstroll = true so It knows it the first roll when it goes into the loop again. Incase you didnt win or los on the first turn firstRoll gets set to false in the default case statement..
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I run it this is what I get
Die 1 - 3
Die 2 - 3
Sum Is - 4
Point Is - 4
Wins - 498
Loses - 502
Chance of Winning - ""
Average Turns - 3.483

Not sure where the 0 comes in, or "what should be a very large number(ex 200 or 300)"

The display would probably be much better if you changed from FlowLayout to GridLayout
 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check the numbers on the command prompt in the back of the applet, thats what im talking about. New code that has chance of winning:

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at the start of the for loop, turns is set to 0
on entry to the while loop, rollDice() is called;
rollDice() contains turns = turns + 1;
i.e. turns with a value of 0 can never be used

 
doburomirushii nikku
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! So sorry having you go through my program like this. In the future I will hopefully not have a problem like this. Thanks again.
 
Look! I laid an egg! Why does it smell like that? Tiny ad, does this smell weird to you?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic