File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Actually I'm lost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Actually I Watch "Actually I New topic
Author

Actually I'm lost

mike statham
Greenhorn

Joined: Feb 24, 2012
Posts: 16
Create a java program that accepts student names and test scores from a file and displays their name, average score and letter grade to the screen. Your program will then display summary information as explained below.

For testing, create an input file with at least 4 students with 3 grades per student like the following:

Connie 82 95 79
James 97 99 80
Susan 15 67 75
Jake 72 65 62
Karen 82 72 78

Name the file grades.txt.
Your program must use a looping structure to read the file, calculate each students average scores then display the students name, their average and letter grade as shown below.

Your program also must count the number of students who earned an A, B, C, D and F. Also, calculate the average grade for the entire class.

You program MUST use a looping structure to read the file and to process each students average score (inner loop).

EXAMPLE Output:

Connie has an average grade of 85.33%. You will receive a B in this class.
James …….
For each student…

Overall Class Average is 78.23%

The following lists the number of students earning each letter grade:

A = 2
B = 1
C = 5
D = 2
F = 1





Error I get is: Exception in thread "main" java.lang.NullPointerException
at Grades.main(Grades.java:19)
But I'm sure that there is more
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
So which object is null? (Hint: It's an object that you're actually assigning null to. :-)
Rod Singh
Greenhorn

Joined: Feb 10, 2012
Posts: 16
Modify the line :
int[] numGrade = null;

as
int[] numGrade = new int[20];
mike statham
Greenhorn

Joined: Feb 24, 2012
Posts: 16
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Grades.main(Grades.java:26)

Is what I get after applying the suggestion todo the the following
int[] numGrade = new int[20];
Marco Galea
Ranch Hand

Joined: Mar 30, 2011
Posts: 30
mike statham wrote:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Grades.main(Grades.java:26)

Is what I get after applying the suggestion todo the the following
int[] numGrade = new int[20];


Hi there first of all in your for loop you should write :


since the array has 20 elements and starts storing elements from 0 to 19

secondly the letterGrade[] you specified that it has 2 elements in line 10 when in reality it should i suppose have 20 aswell since it's using the same variable 'i' !!
Rod Singh
Greenhorn

Joined: Feb 10, 2012
Posts: 16

[DELETED]
mike statham
Greenhorn

Joined: Feb 24, 2012
Posts: 16
Thank you, Rod Singh...But I see I still have alot too learn. Your works!!

I'm looking at yours and mine and letting my brain try to wrap around it.

I don't think your a greenhorn by any means, again thank you and everyone else!
Rod Singh
Greenhorn

Joined: Feb 10, 2012
Posts: 16
You're welcome!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Actually I'm lost