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 So far... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "So far..." Watch "So far..." New topic

So far...

Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
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
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

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.

Junilu - [How to Ask Questions] [How to Answer Questions]
Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
Na its great advice, thanks alot.
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 135
Tip: Try to use more specific subject lines. The more meaningful your subject, the more meaningful your replies.
I agree. Here's the link:
subject: So far...
It's not a secret anymore!