Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

better ideas needed  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have a better way to complete this dice game without using the if loop?


 
Ranch Hand
Posts: 255
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try switch block.
http://download.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
 
author
Marshal
Posts: 23436
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

John Aris wrote:Does anyone have a better way to complete this dice game without using the if loop?



To be fair, as a side thread, a "better way to complete" implies that the game is complete, and it isn't. Once a point is established, then the rules change and you need to implement the next roll.

Henry
 
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Henry Wong wrote:Once a point is established, then the rules change and you need to implement the next roll.Henry


just because i'm a pedant...

the rules don't 'change'. The rules for craps are well established before any roll of the dice. Yes, a subset become active and another become inactive, but the rules do not 'change'.

but you are correct that more code is needed.

Also, since I'm in a pedant mode, there is no such thing as an 'If LOOP'. You have an if STATEMENT.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!