炎炎設(shè)計(jì)
2023-11-10 17:05:40
我應(yīng)該創(chuàng)建一個(gè)程序來(lái)執(zhí)行以下操作:學(xué)生在學(xué)期內(nèi)必須參加兩次測(cè)驗(yàn)和兩次考試。最終成績(jī)的計(jì)算中將剔除一項(xiàng)測(cè)驗(yàn)和一項(xiàng)考試。剩余測(cè)驗(yàn)占最終成績(jī)的 40%,考試占最終成績(jī)的 60%。最終成績(jī)按直線計(jì)算:90%及以上為“A”,低于90%至80%為B等。該程序應(yīng)允許教授輸入學(xué)生姓名、身份證號(hào)碼、兩個(gè)測(cè)驗(yàn)分?jǐn)?shù)和兩次考試成績(jī),然后計(jì)算并輸出學(xué)生的最終成績(jī)。下面是我寫(xiě)的代碼。它執(zhí)行得很好,沒(méi)有任何錯(cuò)誤,我感覺(jué)我已經(jīng)正確地完成了所有事情;但是,無(wú)論我輸入什么分?jǐn)?shù),程序都會(huì)返回字母等級(jí)“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貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
你的問(wèn)題是這一行:
return ((quizScore * .4)+ (examScore * .6))*100;
在這里,您將您的分?jǐn)?shù)乘以該分?jǐn)?shù),這100將給您一個(gè)類似于7100應(yīng)有的分?jǐn)?shù)71(顯然在上面90.0)。刪除100乘法就可以了:
return ((quizScore * .4) + (examScore * .6));
測(cè)試運(yùn)行:
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
這是假設(shè)您輸入的分?jǐn)?shù)75%為75。
添加回答
舉報(bào)
0/150
提交
取消