Results 1 to 7 of 7
 11012013, 06:26 PM #1Member
 Join Date
 Nov 2013
 Posts
 3
 Rep Power
 0
Help Please : Finding average of dice rolls
Problem Description
In this lab you will create and use a dice rolling simulator by using Java's random number generator:
int die = (int)(Math.random() * 6 + 1);
will result in either 1, 2, 3, 4, 5, or 6. Make sure you understand why.
Your program must do the following:
1. Prompt the user to enter the number of times to roll a sixsided die. The user can roll a die
no more than 10 times. If the user inputs a value less than 1 or greater than 10, the user should
be prompted again until an "valid" input value is read.
2. Use a loop that iterates the appropriate number of times and does the following:
"rolls the die" by getting a random value between 1 and 6
adds the roll value to a variable that keeps track of the sum of all roll values
outputs the roll value
increments a counter variable used to keep track of how many times the loop has iterated
Sample run(s):
Enter number of rolls (110): 5
Roll: 5
Roll: 3
Roll: 5
Roll: 3
Roll: 6
Average roll: 4.4

Enter number of rolls (110): 0
Invalid entry!
Enter number of rolls: 11
Invalid entry!
Enter number of rolls: 10
Roll: 1
Roll: 6
Roll: 1
Roll: 3
Roll: 4
Roll: 2
Roll: 5
Roll: 1
Roll: 3
Roll: 5
Average roll: 3.1
 11012013, 06:30 PM #2
Re: Help Please : Finding average of dice rolls
If you don't understand my response, don't ignore it, ask a question.
 11012013, 06:36 PM #3Member
 Join Date
 Nov 2013
 Posts
 3
 Rep Power
 0
Re: Help Please : Finding average of dice rolls
import java.util.Scanner;
public class Lab08
{
public static void main (String[] args)
{
Scanner stdIn = new Scanner(System.in);
int roll;
System.out.print("Enter number of rolls (110):");
roll = stdIn.nextInt();
while (!(roll<=10 && roll>=1))
{
System.out.print("Enter number of rolls (110):");
roll = stdIn.nextInt();
}
for (roll)
{
int die = (int)(Math.random() * 6 + 1);
}
stdIn.close();
}
}
 11012013, 06:50 PM #4
Re: Help Please : Finding average of dice rolls
Can you post the program's output and add some comments showing what is wrong with it.
Please edit your post and wrap your code with code tags:
[code]
YOUR CODE HERE
[/code]
to get highlighting and preserve formatting.If you don't understand my response, don't ignore it, ask a question.
 11012013, 07:00 PM #5Member
 Join Date
 Nov 2013
 Posts
 3
 Rep Power
 0
Re: Help Please : Finding average of dice rolls
Java Code:import java.util.Scanner; public class Lab08 { public static void main (String[] args) { Scanner stdIn = new Scanner(System.in); int roll; System.out.print("Enter number of rolls (110):"); roll = stdIn.nextInt(); while (!(roll<=10 && roll>=1)) { System.out.print("Enter number of rolls (110):"); roll = stdIn.nextInt(); } for (roll) { int die = (int)(Math.random() * 6 + 1); } stdIn.close(); } }
Last edited by Norm; 11012013 at 07:22 PM. Reason: Added / in ending code tag
 11012013, 07:23 PM #6
Re: Help Please : Finding average of dice rolls
Can you post the program's output and add some comments showing what is wrong with it.
If there are error messages, copy the full text and paste it here.If you don't understand my response, don't ignore it, ask a question.
 11032013, 08:39 AM #7Member
 Join Date
 Sep 2009
 Posts
 16
 Rep Power
 0
Re: Help Please : Finding average of dice rolls
I am having troubles to understand what is happening here, but if you need average numbers,
then you will need sum of all numbers and then to divide to the number of elements, in your case number of trows.
Average  Wikipedia, the free encyclopedia.
So if roll is the number of rolls, then you will have (die_1+die_2+...die_roll)/roll. die_1 is the value of the die into the first roll.
Java Code:int sum =0; for(int i = 0; i < roll; i++){ die = ....; sum += die;} double avg = ((double)sum)/roll.
Similar Threads

Finding Min/Max/Average/Sum in an Array.
By tonythekid92 in forum New To JavaReplies: 2Last Post: 09172013, 04:45 AM 
Slight help on program that rolls dice amount of times and counts rolls of snake eyes
By kbc080 in forum New To JavaReplies: 3Last Post: 10162012, 10:47 PM 
Problem in Finding the Mode of Dice Roll Outcomes? Help?
By Kratos321 in forum Advanced JavaReplies: 1Last Post: 05112011, 03:21 AM 
finding average in 2d arrays
By the beginner in forum New To JavaReplies: 18Last Post: 02242011, 04:32 AM 
need some help finding average on java
By jtw0812 in forum New To JavaReplies: 2Last Post: 09292010, 04:26 AM
Bookmarks