This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find the average of arraylist containing database values

 
partha phukan
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...! Can anyone help me to get out of my problem. I could not able to find the average of an arraylist which contains database values. I am using java swing.

i have a database table with 4 fields. i have stored the values from the table using getDouble() method in 4 separate arraylist. Now i need to calculate the average of those 4 arraylist separately and display in 4 Jlabels.

I have 2 classes- one class where i declare the database connections and another class where i need to display the returned values in JLabels by calling the appropriate method of the database class.

Now, where i need to do the average calculation- whether in the database class or in the class where i display the JLabels? What to return from the method in the database class?

i don't know whether i could able to explain you properly or not. Sorry, for my english.

Thank you in advance.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about a separate helper class? It would have a static method which would accept the List of doubles and return the average as a double?
This question is not really related to GUIs. I will move it to a more appropriate forum.
 
partha phukan
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir for your suggestion.

But "a class with static method which would accept the List of doubles"- i am not fully understood about this line. how to accept as the list of doubles? whether i have to declare another arraylist and add all the 4 arraylist and return the new arraylist from the method of the database class?

again you said that "return the average as a double from the separate helper class"- whether it will return separately the 4 average value?

Please clear me. I am not sure how to proceed. Thank you once again.
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Do you know how to write methods? Just declare them as static.
2) Do you know what method arguments are? You need to pass your list as an argument to the method
3) You need to find the average of data in a list right? You got four lists so you should end up with 4 different doubles. So you need to call this method 4 times and pass the 4 different lists to it and get back 4 different average values
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic