• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Grade Averaging and Letter Grade Project

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again Javaranch!

I am currently working on a project that asks the user to enter in two test grades for four different students, once you have the test grades, it gives you the average of both of the students test grades, followed by a letter grade to correspond to it.
I have everything working except for the letter grade part!!! I cant figure out how to make it present a letter grade(A, B, C, D, F) based on the average of both test scores.

Here is my code so far!
Please explain your reasoning behind your logic!!!

------------------------------------------------------------------------------------------------------------------------------------------------------



--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to index into your array of grades using the actual average itself (not the iterator variable).

Also, what happens when there is a fractional value? say 3.5 average.
Array indexes can only be integer!

I would suggest writing a helper method that takes the average as a parameter and returns the grade.
e.g:


WP
 
Chris Hathaway
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I did some messing around and i got it to display the letter, but now its just displaying the wrong letter grade

heres what i added!
---------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why you are changing the values in the "grade" array.
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Paul C's comment. Also, consider this: if you had a score of, say, 65, which of those if statements will evaluate to true? I think I know which one you want to be true, but if you look at the code you've actually got written, which one will actually be true first?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your if statement does not set the grade, it just jumbles up your 'grades' array. Consider making 'grades' final (that way you cannot manipulate it by mistake), then create a char to set each students grade. However, Williams' suggestion is probably best (using a getGrade method) and cleanest. This way, you could just call the method from your println statement.

Also remember that when you are testing a range of values, there is a beginning, AND an ending parameter or you will have...strange things happen. Yes, as William stated you could also work backwards and evaluate from the bottom up. But in the beginning stages, you'd probably be better off sticking to redundancy as a failsafe, then 'take off the training wheels' so to speak.

- VS
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic