This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Counting in Array List/ Standard deviation

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point..lol. Thanks for the help tonight. Ron
 
Ron Ingram
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To follow up in case someone is left working the same problem, I've completed this program using the following Dataset class:

 
I'm still in control here. LOOK at this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!