• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Actually I'm lost

 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2675
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So which object is null? (Hint: It's an object that you're actually assigning null to. :-)
 
Rod Singh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modify the line :
int[] numGrade = null;

as
int[] numGrade = new int[20];
 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[DELETED]
 
mike statham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic