Hey guys. I just signed up and was hoping someone could help me out here. So for this program that's an assignment for my CS 1410 class.There's 2 dices and im suppose to do 1 million rolls. The program is suppose to calculate percentage of how many times the following things occur:

1. Each die has a value of one (Snake Eyes)
2. Each die has the same value (Doubles)
3. The sum of the two dice is seven (Sevens)

The output should look something like this:

------------------------------------------------
Snake eyes occurred x.xxxx percent of the time.
Doubles occurred x.xxxx percent of the time.
Sevens occurred x.xxxx percent of the time.
------------------------------------------------

I just need some guidance on the calculation and displaying the output. Any advice and support related to this is appreciated!

Ok so here's what I have so far:

import java.util.Scanner;
import java.util.Random;

public class DiceExperiment
{

   public static void main(String[] argv)
	{ 

		int Dice_1 = 0;
		int Dice_2 = 0;
		int Dice_Rolls = 0;
		double Snake_Eyes_Counter = 0.0;
		double Doubles_Counter = 0.0;
		double Sevens_Counter = 0.0;
		
		Random generator1 = new Random();
		
		int r = generator1.nextInt(6)+1;
	
	while (Dice_Rolls <= 1000000)
	{
		
		
	}
			
	System.out.println("Snake eyes occured: ");
	System.out.println("Doubles occured: ");
	System.out.println("Sevens occured: ");
		
	}
	

}

System.out.println("Snake eyes occured: ");

I'd recommend that you include a variable in the print out to show the value.

Please use code tags (from icon at upper right) when posting your code to preserve formatting.

Your code is pretty bare bones. There is no logic in it yet.

Do you have a design for how the program is to work? We'll need that to help you correct your code to fit your design.
What are the steps needed to solve the problem?

Some recommendations:
Add code to increment the loop control variable to enable the loop to terminate.
While testing the code, only loop a small number of times(say 20) until you get the logic working. Once you are sure its ok, change it to the large number.

Umm... I was thinking of using If and else statements in the while loop. I want each dice to produce a random number. so if the dice got snake eyes, it would increment 1 for the snake eyes count. the other conditions would be in an else if and an else statement. I'm sorry if that didn't make any sense, my programming skills are still in the beginner stage.

That sounds like a reasonable approach. Code it up and see what happens.
Do the program in small steps
Get the loop working.
Get the two dice rolls
Do one of tests.
Report the results

Use println()s to show the values of variables as the code moves from statement to statement.
Later you can comment them out when you get a section working.

Within the loop im trying to get each dice to produce a random number ... that's the problem im at right now, i dont know how to get the dice to do that. i think i might actually be able to finish the rest once i understand that but i dont know lol

int r = generator1.nextInt(6)+1;
What does the above do?
put it in a loop and print the value of r for a few times.

You're getting good advice on your logic from Norm, I have nothing to add there. A matter of style that might help you out, though, is to replace the constant "1000000" in your loop with a final variable, declared like this
private final NUMBER_OF_TIMES_TO_ROLL = 1000000;
or some similarly expressive name.

If you then make your loop read
while (Dice_Rolls < NUMBER_OF_TIMES_TO_ROLL)

then it's a little easier to change the number of times you throw the bones, and it's more clear what the loop is doing. A for loop would be clearer still, and in a for loop it's a lot harder to omit the step of incrementing your loop control variable! :)

I now return you to Norm's capable guidance.

thank you good sir, I'll give it a go

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.