• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 10930
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to use 25
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Marshal
Posts: 79974
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic