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 +

Edited by Prisms: n/a

7 Years
Discussion Span
Last Post by JamesCherrill

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


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

Edited by JamesCherrill: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.