したがって、コードの 5 行目[if(length == 2 || 1)]
で、or ステートメントで演算子 || を指定するとエラーが発生します。引数の型 boolean、int については定義されていません。構文のどこが間違っているのか、どうすれば修正できるのかについてのアイデアはありますか? ありがとう!
//Write a program that translates a letter grade into a number grade. Letter grades are
//A B C D F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0.
//There is no F+ or F-. A + increases the numeric value by 0.3, a - decreases it by 0.3.
//However, an A+ has the value 4.0. All other inputs have value –1.
//Enter a letter grade:
// getNumericGrade メソッドでクラス Grade を使用します。
public class Grade {
private double grade = 0.0;
public double getNumericGrade(String letterGrade){
int length = letterGrade.length();
if(length == 2 || 1){
char startChar = letterGrade.charAt(0);
char endChar = letterGrade.charAt(1);
switch(startChar){
case 'A':
this.grade = 4.0;
break;
case 'B':
this.grade = 3.0;
break;
case 'C':
this.grade = 2.0;
break;
case 'D':
this.grade = 1.0;
break;
case 'F':
this.grade = 0.0;
break;
default:
this.grade = -1;
}
if(length == 2){
switch(endChar){
case '-':
this.grade = this.grade - .3;
break;
case '+':
if(startChar != 'A'){
this.grade = this.grade + .3;
}
break;
default:
this.grade = -1;
}
}
if(startChar == 'F' && length != 1){
this.grade = -1;
}
}else{
this.grade = -1;
}
return this.grade;
}
}