954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Saving numbers to Letters

Hey guys I was wondering if I was doing this right or not. I am writing a program that asks for a grade like A, -A, B+, -B, B and so on. each letter grade is equal to a certain number like in a persons GPA, A = 4.0, -A = 3.67, B+ = 3.33. I want the user to enter the letter grades and have the numbers factored into the GPA. I have already written the program and it works when the numbers are entered but how do you save the numbers to the letter grades? Thank you.

Things I tried:

char A = (double)4.0;

This wont work for the - or +

Prisms
Light Poster
27 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 
how do you save the numbers to the letter grades


You could use a Map. The key is the letter and its value is the numeric value

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Norm's right - there's a class called Map that you could use, but I suspect that this a bit advanced for your stage of learning, and that your teacher had something more basic in mind. Java has no in-built knowledge of raed letters and numbers, so there's no automatic way to do this, but you can use some if tests, like this (pseudo code, not actual Java syntax!)

if (grade letter is A) number = 4
else if (grade letter is A-) number = 3.67
etc
JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: