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

Help with Control Structures.

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


Thanks,
Philip Herzer
[ September 23, 2004: Message edited by: Philip Herzer ]
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Philip,
You should put an return (or exit statement) statement after printing the winner, so no further execution will take place.

Regards,
Kalai Selvan T.
 
Kalai Selvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OOps i am bit late and not as descriptive as Nigel Browne
 
Every time you till, you lose 30% of your organic matter. But this tiny ad is durable:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic