This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a method to average grades out

 
B Mart
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am creating a program to average grades from an array. As you can see, I can load the array properly but now I need to send the info to a method and then have it dispense the name of the student (stored in one array) and the average grade of each student (taken from the data from another array). Any help would be amazing!

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the connection with Servlets?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch! I added [ code ] tags to your post to make it easier to read. I'm going to move this thread to our beginning java forum where it fits better.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know how to create a method that just prints "hello world"? How about printing out the name of each student?
 
Callum Ludwig
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couldn't line 19. be:



Then in the for loop that starts at line 35. You could initialize an integer or double primitive (depending on whether to display decimal places) so line 36 could be replaced with:



So for each student the grade average variable would be reset then as you get iterate through the inner loop you total up the grades then you could have at the end of the inner loop (after the enclosing curly brace) which totals the grades the following:



The above is a hard-coded length but I'm sure you can get this length from one of the arrays. Depending on the displaying decimal places you could use a primitive double or integer. And then use a formater to determine the maximum number of decimals to display if you are displaying decimal places.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic