Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (595) Games in Android Showcase (168) games submitted by our members Games in WIP (646) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Hey guys. Problem with calculating averages.  (Read 1151 times) 0 Members and 1 Guest are viewing this topic.
Hauk

Junior Devvie

Guitar, Norse Mythology, java and women=life

 « Posted 2005-11-22 22:28:01 »

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.

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54 `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

I want to become a hermit and live in the harsh wastelands of Norway. I want to have a cloak made of bearskin and hunt the demons of the night.

I was born for a reason and am not about to lie down and die like the rest of you. Anybody with me?
swpalmer

JGO Coder

Exp: 12 years

Where's the Kaboom?

 « Reply #1 - Posted 2005-11-23 04:18:23 »

Sounds suspiciously like someone's homework.

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

Hauk

Junior Devvie

Guitar, Norse Mythology, java and women=life

 « Reply #2 - Posted 2005-11-23 12:28:07 »

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

I want to become a hermit and live in the harsh wastelands of Norway. I want to have a cloak made of bearskin and hunt the demons of the night.

I was born for a reason and am not about to lie down and die like the rest of you. Anybody with me?
jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

 « Reply #3 - Posted 2005-11-23 18:01:49 »

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.

Java Game Console Project
Last Journal Entry: 12/17/04
Hauk

Junior Devvie

Guitar, Norse Mythology, java and women=life

 « Reply #4 - Posted 2005-11-23 23:41:59 »

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

Hauk

I want to become a hermit and live in the harsh wastelands of Norway. I want to have a cloak made of bearskin and hunt the demons of the night.

I was born for a reason and am not about to lie down and die like the rest of you. Anybody with me?
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 deepthought (47 views) 2015-06-30 15:39:44 deepthought (50 views) 2015-06-30 15:39:09 deepthought (62 views) 2015-06-30 15:36:52 Za\'Anzabar (37 views) 2015-06-29 05:44:54 TritonDreyja (46 views) 2015-06-24 17:10:40 CopyableCougar4 (46 views) 2015-06-23 00:34:45 BurntPizza (52 views) 2015-06-21 20:36:46 cookiecompiler (93 views) 2015-06-11 15:42:53 cookiecompiler (55 views) 2015-06-11 15:41:14 NegativeZero (80 views) 2015-06-11 09:49:18
 princec 29x wessles 22x BurntPizza 19x CopyableCougar4 19x opiop65 17x ags1 15x nsigma 15x EgonOlsen 14x Riven 13x theagentd 12x KaiHH 12x SauronWatchesYou 11x KevinWorkman 11x Archive 11x sunburn 11x NegativeZero 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org