aspose file tools*
The moose likes Beginning Java and the fly likes Counting in Array List/ Standard deviation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Counting in Array List/ Standard deviation" Watch "Counting in Array List/ Standard deviation" New topic
Author

Counting in Array List/ Standard deviation

Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Hello all,

I'm working on an assignment that I can't seem to get my arms around. Basically, I have to supply values and count the number of entries, provide a sum for each number added,an average and standard deviation. Right now, I'm trying to correctly add each entry into the list and get the count, sum and average. For some reason, it doubles each entry within the LIst, so that if I provide one entry of '5', it adds it twice when getting the sum.

Please review what I have and provide any/all the help you can. Thank you.

This is the tester class:



Here is the dataset class
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Yep.

On row 34 you add the new number to the sum.

On row 43 you start to loop and add the new number again.

Why not make a method that sums it up when asked to do it? One method should do one thing. Add-method should add the number to the list, sum-method return the sum. avg-method the average.
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Hello,

Yes, I'm working towards cleaning it up, but I'm really stuck on the array. I've corrected and here is the new Dataset class and output. Seems to still be doubling in the add() method.




Output:

Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

Ask yourself: Why do I need to loop through all the numbers already added in the list and for every number found there, add x to the sum?

I've done something like this:

Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
Good point..lol. Thanks for the help tonight. Ron
Ron Ingram
Ranch Hand

Joined: Mar 11, 2011
Posts: 63
To follow up in case someone is left working the same problem, I've completed this program using the following Dataset class:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Counting in Array List/ Standard deviation