我应该创建一个程序来执行以下操作:学生在学期内必须参加两次测验和两次考试。最终成绩的计算中将剔除一项测验和一项考试。剩余测验占最终成绩的 40%,考试占最终成绩的 60%。最终成绩按直线计算:90%及以上为“A”,低于90%至80%为B等。该程序应允许教授输入学生姓名、身份证号码、两个测验分数和两次考试成绩,然后计算并输出学生的最终成绩。下面是我写的代码。它执行得很好,没有任何错误,我感觉我已经正确地完成了所有事情;但是,无论我输入什么分数,程序都会返回字母等级“A”。public static void main(String[] args){ //Declare all variables String name; String idNum; int q1; int q2; int e1; int e2; int bestQuiz; int bestExam; double score; char letterGrade; Scanner kbd; kbd = new Scanner(System.in); System.out.println("Enter student's name: "); name = kbd.nextLine(); System.out.println("Enter student's ID number: "); idNum = kbd.nextLine(); System.out.println("Enter the quiz scores: "); q1 = kbd.nextInt(); q2 = kbd.nextInt(); System.out.println("Enter the exam scores: "); e1 = kbd.nextInt(); e2 = kbd.nextInt(); bestQuiz = max(q1, q2); bestExam = max(e1, e2); score = computeRawPercentage(bestQuiz, bestExam); letterGrade = finalGrade( score ); System.out.print(name + " " + idNum + " "); System.out.println("Final Grade: " + letterGrade); } //Max method public static int max(int n1, int n2){ int big; if (n1 > n2){ big = n1; } else { big = n2; } return big; } //computeRawPercentage method public static double computeRawPercentage(int quizScore, int examScore){ return ((quizScore * .4)+ (examScore * .6))*100; } //finalGrade method public static char finalGrade(double grade){ char letterGrade; if (grade >= 90.0) letterGrade = 'A'; else if ((grade >= 80.0)&&(grade < 90.0)) letterGrade = 'B'; else if ((grade >= 70.0)&&(grade < 80.0)) letterGrade = 'C'; else if ((grade >= 60.0)&&(grade < 70.0)) letterGrade = 'D'; else letterGrade = 'F'; return letterGrade; } }
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
你的问题是这一行:
return ((quizScore * .4)+ (examScore * .6))*100;
在这里,您将您的分数乘以该分数,这100将给您一个类似于7100应有的分数71(显然在上面90.0)。删除100乘法就可以了:
return ((quizScore * .4) + (examScore * .6));
测试运行:
Enter student's name:
TestName
Enter student's ID number:
12345
Enter the quiz scores:
55
65
Enter the exam scores:
65
86
77.6
TestName 12345 Final Grade: C
这是假设您输入的分数75%为75。
添加回答
举报
0/150
提交
取消