• Post Reply Bookmark Topic Watch Topic
  • New Topic

Possible source(s) of null returns  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!  Our class has just started using OOP, and I am working on an assignment.  It basically is supposed to read an external file on quiz/test grades for students, and then is supposed to calculate the final percentage grade as well as the letter grade, than printing out all of the values. I have been getting values of null for the last two values (The final percentage and the final grade, which I have to call from the student class).  I know that this is likely some extremely rookie mistake, but I just can't seem to solve it.   Here is what I have...

The Runner



Student Class


   
 
Classroom Class (I do not believe it is relevant to the bug)



....And this is my Output

Student Quiz1 Quiz2 Midterm Final Final% Grade
1              8               7              89            94     0.0           null
2              9               6              77            90     0.0           null
3              10             10            65            88     0.0            null
4               7              5              80            81     0.0            null

Any help would be appreciated!
 
Master Rancher
Posts: 2045
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the very first glance, have a look at line 36 of the Student_Tester class:

I think that that should be

Another idea is to add the methode 'toString' to your Student class, and after creating a new Student, print it out to see if the reading of the data went well.

So far from now.
 
Lisa Hammond
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Piet!

I fixed that issue that you pointed out, and I created a test method to see if the values were being properly saved (they were, funnily enough)

 
Lisa Hammond
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I played around with this for another hour, and cannot seem to find the source of my problems.  Could it be the way I am defining my methods?  Could it be in relation to my usage of the array for declaring the student-objects?  I am well and truly clueless.
 
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LetterGrade will be null until you call makeLetterGrade().
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wecome to the Ranch

Why does your letter grade method have public access? Consider whether it would be better called only from inside your class, in which case it would want private access.
In the same method, please look carefully what mark you would get for 89%
I suggest you avoid >= and <= if you can use < or > insterad. Not that there is anything actually wrong with <= and >=, but the other two operators are easier to read. You would have to choose an order for the successive if‑elses; sometimes they shou‍ld go in ascending order and sometimes descending.
 
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java naming convention is for variable and method names to start with a lowercase letter. Names of types like classes, interfaces and enum start with a capital letter. When you don't follow these conventions in your code, it makes it harder for other people to read it. Your variables like LetterGrade should be letterGrade instead.
 
Bartender
Posts: 572
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Campbell Ritchie suggested, look closely at your makeLetterGrtade() method and see what letter you would assign to a score of 89. Or 60. Or 77. or anything less than 90.

Also, be very careful when you make a divide operation using integers.  For example, with this line:
what value would mtWeighted be if MidTerm were 3? or 2? or 1?
Also, you should get into the habit of adhering to the Java convention of naming all of your variables with a lower-case letter; therefore "midterm", not "ModTerm".
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!