• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding the average of a multidimensional array.  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The method I am having issues with is the "printStudentReport" method. I am trying to calculate the average of a randomly generated number of students and tests. My professor has been sick and basically told us to "figure it out." Any advice would be helpful. For my "printTestReport" method, I have to calculate the average of the test by test number.

 
Marshal
Posts: 58424
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Do you have a Test class?
 
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your average needs to be the sum of all the test scores for a student. So first calculate the sum, then at the end, calculate the average.
 
Sheriff
Posts: 11747
191
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zach Follmer wrote:I have to calculate the average of the test by test number.


As I understand this, you need to get the average score that students got on a particular test. So if there are 2 students who took Test#1 and student 1 scored 50 and student 2 scored 100, the average for Test#1 would be 75. If those same two students took Test#2 and scored 80 and 90, respectively, the average for Test#2 would be 85. Correct?

As a student, you should try to figure it out. Our usual advice is to do it first with pen and paper. How would do this manually?

I'll give you a hint though: you should use another array to hold the totals of the scores for each test. That is, if you have 5 tests, then you should have an array, say int[] totals and make it big enough to hold the total of the scores for each of those 5 tests. Since you know how many students there are, it's an easy thing to iterate through this array and calculate the average for each test.

Good luck.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!