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.
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.
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.
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
subject: How to find the average of arraylist containing database values