The moose likes Beginning Java and the fly likes Creating a method to average grades out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a method to average grades out" Watch "Creating a method to average grades out" New topic

Creating a method to average grades out

B Mart

Joined: Mar 08, 2011
Posts: 5

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

Joined: Jan 10, 2002
Posts: 60773

What's the connection with Servlets?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30076

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30076

Do you know how to create a method that just prints "hello world"? How about printing out the name of each student?
Callum Ludwig

Joined: Feb 20, 2011
Posts: 13
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: Creating a method to average grades out
Similar Threads
Puzzle for JavaProgrammers
? about creating a method
Keep getting this error and not sure why
Getting the average to display
java error