Hey guys. Problem with calculating averages.

Hey guys, haven’t been here in ages, but anywho, I’ve a huge problem.

What I’m trying to do is test the “dice” 20 times to check its randomness. The program is meant to record the most amount of times the numer appeared, the least amount of times the number occured, and the average.

I’ve managed to get the program to calculate the amount of times a number occured, but I’m having trouble with the average, and the most amount of times it occured and the least amount of times it occured.

public class  TestRandomness
{
	static int rolledNumber()
	{
		int rolledNumber = (int) (1 + (Math.random() * 6));

		return rolledNumber;
	}

	static double getAverage()
	{
		double takenAverage;

		for(int r = 1; r <= 20; r++)
		{
			takenAverage = ((counts[r] + 1) / 6);

			
		}
			return takenAverage;

	}

	public static void main(String [] args) 
	{
		System.out.println("How many times do you want to throw the dice: ");

		int UserAmount = Console.readInt();
		int [] counts = new int [7];
		int [] averages = new int [7];

		for(int y = 0; y <= 20; y++)
		{

			for(int i = 1; i <= UserAmount; i++)
			{
				int returnedNumber = rolledNumber();

				counts[returnedNumber] = counts[returnedNumber] + 1;
			}


		}
		
		for(int x = 1; x <= 6; x++)
		{
			System.out.println(x + ": " + counts[x]);
		}

		

		
	}
}

I would try and figure it out myself, I truly would, but I’ve run out of time, and desperately need it done!

Thanks for any help guys!

Hauk

Sounds suspiciously like someone’s homework.

Explain what you are trying to do in your game that requires these numbers.

Okay, what we have to do is roll a dice a certain amount of times(integer read by console), then we have to get the amount of times each of the numbers on the dice came up. Then we have to repeat this process twenty times, calculating the average of the the elements in the array. THEN, we have to get the maximum amount of times a number came up in either of the user-requested ‘amount of times’, the mimimum amount of times a number came up.

Yes it is homework, but even if you didn’t post up any code and just gave me a guiding direction, it would be greatly appreciated. Its just I’ve run out of time to get this done, and I need some help, so I thought I’d ask the community.

Thanks guys!

Hauk

Well, at least he’s honest about it.

Hauk, can you figure the problem out on paper? If you understand the problem well enough to track the values and get the result on paper, then the programming should be a cakewalk. If you can’t do it on paper, then you probably don’t understand what your Professor is asking you to do. If you don’t understand, then you need to ask him for clarification.

Hmm, okay. I did try working it out in pseudocode, i’ll try it again in even simpler english.

P.S I’m not going to bed until its done! :’(

Thanks guys, I knew I could rely on you ;D

Hauk