D Doemer

Ranch Hand

Posts: 36

posted 3 years ago

Hi everyone,

I apologize in advance for the length. This is such a nit-picky question I'm rolling my eyes at it as I'm writing it.

The directions for this assignment are:

1. Create a class called Dice to represent a single cube. It should have a method called roll() that randomly selects a number from 1 to 6 for the value of the dice.

2. Create a test main method for the Dice class that creates a Dice, and rolls it many times.

3. Can you keep track of how many times each number comes up? Describe how in a three or fewer sentences, or implement it in your main program.

4. Describe which number comes up the most often in a sentence. Back your answer up with your statistics if possible.

The pieces I've highlighted in red are what I'm having trouble with. I've created a Dice program as follows.

My issues:

1) The output for the Dice program is showing 10,000 random #'s between 1 and 6.

(I.e. --

run:

3

1

6

4

3

2..............)

Shouldn't it look something like "Dice with 6 sides is showing 1, Dice with 6 sides is showing 4, .....etc.)?

And 2)

The only way I can figure out how to get instruction #3 correct is by adding a separate Dice Statistics class to my program, which I did here:

This gives me the output I need, but clearly the instructor wants this all lumped into the main Dice program. Am I right? Any help would be greatly appreciated.

Thanks

I apologize in advance for the length. This is such a nit-picky question I'm rolling my eyes at it as I'm writing it.

The directions for this assignment are:

1. Create a class called Dice to represent a single cube. It should have a method called roll() that randomly selects a number from 1 to 6 for the value of the dice.

2. Create a test main method for the Dice class that creates a Dice, and rolls it many times.

3. Can you keep track of how many times each number comes up? Describe how in a three or fewer sentences, or implement it in your main program.

4. Describe which number comes up the most often in a sentence. Back your answer up with your statistics if possible.

The pieces I've highlighted in red are what I'm having trouble with. I've created a Dice program as follows.

My issues:

1) The output for the Dice program is showing 10,000 random #'s between 1 and 6.

(I.e. --

run:

3

1

6

4

3

2..............)

Shouldn't it look something like "Dice with 6 sides is showing 1, Dice with 6 sides is showing 4, .....etc.)?

And 2)

The only way I can figure out how to get instruction #3 correct is by adding a separate Dice Statistics class to my program, which I did here:

This gives me the output I need, but clearly the instructor wants this all lumped into the main Dice program. Am I right? Any help would be greatly appreciated.

Thanks

Campbell Ritchie

Marshal

Posts: 56525

172

posted 3 years ago

So, you have a roll() method. Have you got a DiceStatistics class with a count method? I think the class you have written looks too complicated, and you should think again. These things are actually simpler than you think, but having a computer screen in your vision obscures things.

Start by turning your computer off. Do some counting on a piece of paper. The sort of counting where you write |||| for 4 then a line across them for 5. Then get another sheet of paper a pencil and (important) an eraser, and write down how you counted the numbers. If you have difficulty, try counting with a real die. When you have got how you do that process written down really simply, you will find it easy to turn to code.

I think your stats class will require some data structure to do the counting, a count(int i) method and a toString() method which returns a report of counting to date.

Start by turning your computer off. Do some counting on a piece of paper. The sort of counting where you write |||| for 4 then a line across them for 5. Then get another sheet of paper a pencil and (important) an eraser, and write down how you counted the numbers. If you have difficulty, try counting with a real die. When you have got how you do that process written down really simply, you will find it easy to turn to code.

I think your stats class will require some data structure to do the counting, a count(int i) method and a toString() method which returns a report of counting to date.

It is sorta covered in the JavaRanch Style Guide. |