• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

So far...

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far the object of my project is to produce a program that will roll 3 dice, and print out three random values. And display the highest and ask you if you want to keep it, if not it will roll again (2 rolls max). You keep ur value then roll 2 dice, and then 1 dice and keep the highest values and add them together at end.

So far my program looks like.

Am i going in the right direction? Criticism welcomed!

 
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing I could suggest is to re-organize your code/logic a little bit. Writing a program is a lot like writing a story. In a good story, sentences, paragraphs, and chapters are organized so that there is a continuous flow in the story. Similarly, you should write code so that somebody reading it will be able understand the purpose of the program.

Compare these two snippets:



Which version makes its purpose clearer? Reading code should be like reading a story.



If you read the code above from top to bottom, there is a natural progression from high level to low level ideas. Just as a paragraph revolves around a central idea, a method should also revolve around a central singular purpose and each statement in the method should be written towards achieving that single purpose. Don't be afraid to write many methods. Use comments to clarify the purpose of each method but strive to write code that reads the way it is intended to work.

Also, try to follow standard coding conventions. In particular, class names should be start with a capital letter (you declared a class named dice), variables should start with lowercase (you declared a variable name Highest).

Sorry if this seems a bit much for a beginner but hopefully you can see the benefits of such practices.
 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Na its great advice, thanks alot.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tip: Try to use more specific subject lines. The more meaningful your subject, the more meaningful your replies.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic