This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Annoying Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Annoying Error" Watch "Annoying Error" New topic
Author

Annoying Error

doburomirushii nikku
Ranch Hand

Joined: Oct 06, 2004
Posts: 31
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.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 06, 2004
Posts: 31
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 06, 2004
Posts: 31
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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Oct 06, 2004
Posts: 31
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annoying Error
 
Similar Threads
genrating lotto with apllet
Lotto generation
Action Performed Method
Help with this code
Can someone help me out with this code