aspose file tools*
The moose likes Beginning Java and the fly likes Roll the Dice program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Roll the Dice program" Watch "Roll the Dice program" New topic
Author

Roll the Dice program

Nick Cantara
Greenhorn

Joined: Oct 20, 2012
Posts: 1
So I'm writing an application that rolls two six-sided dice, displaying the results after each roll and asking the user if they would like to roll again. It is supposed to show Roll 1, Roll 2, Roll 3, etc, but I am having problems with it showing that based on my counter variable. I have 5 classes created. Below is what I have for code so far.



Not sure about this last one, but the program should have a class called Die that stores the data for each die. This is what I have so far and I'm lost on it.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hi, and welcome to the Ranch!

Wha specific problem are you having? People will be better able to help you if you TellTheDetails(←click).

Also, that's a lot of code, and the vast majority of it is not related to your problem. It will be easier for people to help you (and easier for you to help yourself!) if you write a small program that only shows your problem and doesn't have anything not related to it. An SSCCE(←click).
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8196
    
  23

Nick Cantara wrote:Not sure about this last one, but the program should have a class called Die that stores the data for each die. This is what I have so far and I'm lost on it...

Right, well I'm assuming your Die class is supposed to model a single die, so why would you have a 'sum' field?

Also, it would appear that you're using the 'd' field to hold the number of sides, so why not call it 'numberOfSides'? Giving things meaningful names is a very important part of good programming.

If it's the random number stuff you're stuck on, have a look at the Random class (java.util.Random (←click)).

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11475
    
  16

You are writing too much code at once. Before you ever write a single line of code, you should analyze the problem and come up with all the individual things you need it to do. For example, my first pass at this assignment would be:

1) Generate an integer in the range 1-6
2) compute the sum of two numbers
3) Display a result
4) keep track of the number of rolls
5) ask the user something
6) Get input from a user
7) validate input
8 loop around and do it all again (if needed)


I'd make sure I could do each of the above steps by them selves before trying to combine them. I'd make sure one worked before I considered starting the next.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Roll the Dice program