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 +

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
etc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.