File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Help with Control Structures. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Control Structures." Watch "Help with Control Structures." New topic

Help with Control Structures.

Philip Herzer

Joined: Oct 21, 2003
Posts: 21
I'm trying to write my own Craps game. It is very limited, just to help me get the idea of control structures within java. I tried using nested ifs, but failed to do it properly because in my crap game, the 2nd and 3rd rolls still occur regardless if the player wins in the first rolls, second, or third.

My second attempt was trying to seperate the stuff using switch and using a while control loop. I would appreciate any help on the first attempt and suggestions for improving my second attempt.

First Attempt:

Second Attempt

Philip Herzer
[ September 23, 2004: Message edited by: Philip Herzer ]

"Mejor morir de pie que vivir toda la vida arrodillas."<br /> Emilio Zapata
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
In both cases you do not have an proper exit to your program. Use: to exit the program after a game is complete. Your second version of the method rollDice, it should probably be renamed rollAndTallyTwoDice, because this will produce self-documenting code. The second version of the program has an int rollCounter but doesn't use it. I would use the rollCounter to limit the number of rolls that a player can have and I would also keep a record of the players status, along the lines of:
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi Philip,
You should put an return (or exit statement) statement after printing the winner, so no further execution will take place.

Kalai Selvan T.
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
OOps i am bit late and not as descriptive as Nigel Browne
subject: Help with Control Structures.
jQuery in Action, 3rd edition