Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Hey guys. Problem with calculating averages.  (Read 1044 times)
0 Members and 1 Guest are viewing this topic.
Offline 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?
Offline 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.

Offline 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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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
Offline 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!  Cry

Thanks guys, I knew I could rely on you  Grin

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (22 views)
2014-12-14 19:50:38

BurntPizza (43 views)
2014-12-09 22:41:13

BurntPizza (77 views)
2014-12-08 04:46:31

JscottyBieshaar (38 views)
2014-12-05 12:39:02

SHC (52 views)
2014-12-03 16:27:13

CopyableCougar4 (50 views)
2014-11-29 21:32:03

toopeicgaming1999 (116 views)
2014-11-26 15:22:04

toopeicgaming1999 (106 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!