thanks for looking. I'm stuck on why this is not handling cases for inputted grades. It handles A+ fine (returns 4.0) but 'A' gives an error, 'A-' gives 4.0 (should be 3.7), then 'B+' is correct, 'B' gives error, 'B-' gives 3.0 (should be 2.7), and this is the pattern. Any thoughts?
public class Grade {
private String grade = "";
public Grade(String grade) {
this.grade = grade;
public double getgrade() {
double gpa = 0.0;
char[] gradeArray = this.grade.toCharArray();
if (gradeArray[0] == 'A') {
gpa += 4.0;
}
if (gradeArray[0] == 'B') {
gpa += 3.0;
}
if (gradeArray[0] == 'C') {
gpa += 2.0;
}
if (gradeArray[0] == 'D') {
gpa += 1.0;
}
if (gradeArray[1] == '+') {
if (gradeArray[0] != 'A') {
gpa += 0.3;
}
}
if (gradeArray[0] == '-') {
gpa -= 0.3;
}
return gpa;
}
}```
if (gradeArray[0] == '-') {explains the other issue.A-D,+or-? I'd do some validation in the constructor and throw an exception if necessary...