Need help writing main program for this assignment. The instructions are:
Create a class called Dice to represent a single cube. The class diagram for class is shown. It should have a method called roll() that randomly selects a number from 1 to 6 for the value of the dice.
This is a main program, not JUnit, and it is java.util.Random, not math.Random.
This is what I have so far:
It's the "public static void main() part that I need help with. Right now it's showing up as a bunch of 10000's, but I need it to show the random numbers that are rolled on a dice. Please, please keep it very simple, and thank you so much in advance.
Currently your main method loops 10000 times, and each time prints out the number 10000. You aren't using your instance of Dice at all.
Diana Oswald wrote:Yes, it is supposed to roll the dice randomly and display the results. I gave it 10,000 rolls. I'm not sure how to write a main program, so I don't know how to make it roll anything other than 10,000.
It didn't roll 10000, it can't roll anything outside of the range 1-6. You're getting 10000 because as Ricoo said, that's the value you set into the variable you're printing out. You wrote the roll() method, so you need to call it to get the dice value.
Mike. J. Thompson wrote:You wrote the roll() method, so you need to call it to get the dice value.
This is correct... I was getting ahead of myself with putting new Dice() inside the println() method....
What you need to do is inside the for loop call the roll() method on the dice reference and pass the dice reference as an argument to the println() method to get the value.