• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Counting in Array List/ Standard deviation

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic