Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding grade letter to my array in my grading calculator dont work  RSS feed

 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am new to java and here I have an issue with this code having multiple methods. this is for a grading calculator and ask me how many students, how many grades, and prints the result in an array table...what I want to do is to not just print each mark, but calculate the average and display the average in the array DisplayvalueInArray. my output right now is the student with all the marks for each student.

this is my java code:



my output:


 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Miguel. Welcome to the ranch!

So you're getting a null pointer exception.
I think I've spotted your problem, but lets see if we can point you in the direction to solve it yourself:

Can you identify from the error message which line of code is causing the problem?
Once you have found that line, take a look at it. What is on that line that might possibly throw a null pointer exception? i.e. what variable/object might be null here?
For the things that might be null, where should they be getting their value from?



 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so at the end of the line I have to add the variables averageGrade to be calculated (or add the whole loop to the DisplayvalueInArray method) I am kind of lost on what to do.
 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I think I broke this even more, now it doesn't even do anything, LOL wow.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>so at the end of the line I have to add the variables averageGrade to be calculated (or add the whole loop to the DisplayvalueInArray method) I am kind of lost on what to do.

Huh? You've lost me here.
How did you go with the questions I posed?

 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well to implement my if statements for taking the array values of homework and taking the average, and then with that average put the value through the loop and assign a letter grade and print it together in the DisplayValueArray. That's what I wanted to accomplish, but there is a brake somewhere and I cant figue it out...I still working on it..and now I am starting another one from scratch. But it would be nice if I could figure that code out lol, but I still have a great deal of learning to do, and I understand.
 
Carey Brown
Bartender
Posts: 2982
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lines 6 and 25 both declare studentScoreArray variables. Which one do you want used on line 55?
 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use 25
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now the studentScoreArray on line 55 is the static final one on line 6. It is never used anywhere else. How could you use the parameter studentScoreArray in line 41 in line 55?
 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently adding another method to calculate the grade average, but to link other methods with the new one is what is killing me. I erased line 55. but like I said earlier everything I add something new the more complex it gets and more errors pop up, and I don't have enough experience to figure all out at this point by myself...did I made it to complex to start with? what is supposed to do is use arrays to save multiple students and multiple grades and calculate and be able to assign a grade letter according to the scale.
 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again here I have my newest code, Still have the same problem...the calculateGrade method in line 22I want to get that average and assign it to my GradeLetter method in line 63 and loop it and then the result would be the grade letter which I want to put in the DisplayvalueInArray line 47...but I cant display the grade letter and cant figure it out. below is also my output. thank you guys for your help so far.




I also want to get rid of that null from my result in the scores





 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you pass in

the String will evaluate to "null". What you probably want is:


To get local variables from one method to another, the best way is to use a return type from the method you want a value from and pass that into an argument of the method that wants the value:
 
Campbell Ritchie
Marshal
Posts: 55680
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why have you marked so many methods static?
 
miguel ortiz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, I mark my methods static because is the only way everything is working so far, but I still have the same issue that I cannot calculate the grade letter and print it out with the grades on the array table
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!