• 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Finding the average of a multidimensional array.

 
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: 67330
256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Do you have a Test class?
 
Marshal
Posts: 6615
177
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • 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: 14734
244
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • 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.
 
Get off me! Here, read 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!