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!
Stephen Foy - Microsoft Application Development Consultant
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.