创建程序段,如果用户想接受教师的评估分数或评估信,该程序段将为用户提供帮助。打印教员的姓名和获得的备注。备注(rem)基于以下标准:(备注.java)
SCORE/LETTER REMARKS
4.50-5.00 or A Outstanding
4.00-4.49 or B Very Satisfactory
3.50-3.99 or C Satisfactory
3.00-3.49 or D Needs Improvement
2.99 below or E Poor
请帮助我如何输入要添加到if-else语句中的字母选项。
截至目前,这是我的程序:
Scanner in = new Scanner (System.in);
String n;
float score;
System.out.println("Enter Faculty's Name:");
n=in.nextLine(); //asking the user to incode his/her name
System.out.println("Enter score:");
score=in.nextFloat(); //asking the user to incode score
if ( score >=4.50 )// 4.50 to 5.00
System.out.println("Remark: Outstanding");
else if(score>=4.00)// 4.00 to 4.49
System.out.println("Remark: Very Satisfactory");
else if(score>=3.50)// 3.50 to 3.99
System.out.println("Remark: Satisfactory");
else if(score>=3.00)//3.00 to 3.49
System.out.println("Remark: Needs Improvement");
else
System.out.println("Remark: Poor");
试试这个:
Scanner in = new Scanner (System.in);
String n, score;
System.out.println("Enter Faculty's Name:");
n=in.nextLine(); //asking the user to incode his/her name
System.out.println("Enter score:");
score=in.nextLine(); //asking the user to incode score
if ("ABCDE".contains(score.toUpperCase())) {
if (score.equalsIgnoreCase("a"))// 4.50 to 5.00
System.out.println("Remark: Outstanding");
else if(score.equalsIgnoreCase("b"))// 4.00 to 4.49
System.out.println("Remark: Very Satisfactory");
else if(score.equalsIgnoreCase("c"))// 3.50 to 3.99
System.out.println("Remark: Satisfactory");
else if(score.equalsIgnoreCase("d"))//3.00 to 3.49
System.out.println("Remark: Needs Improvement");
else
System.out.println("Remark: Poor");
} else {
if (Float.valueOf(score) >=4.50)// 4.50 to 5.00
System.out.println("Remark: Outstanding");
else if(Float.parseFloat(score) >=4.00 )// 4.00 to 4.49
System.out.println("Remark: Very Satisfactory");
else if(Float.parseFloat(score) >=3.50 )// 3.50 to 3.99
System.out.println("Remark: Satisfactory");
else if(Float.parseFloat(score) >=3.00 )//3.00 to 3.49
System.out.println("Remark: Needs Improvement");
else
System.out.println("Remark: Poor");
}