我遇到問題。我有這個計劃,我應該創建,它應該讀取兩個測驗的成績,這兩個測驗的總和等於25%的學生總分,期中考試是25%的學生成績和期末考試是總等級的50%。當我運行程序時,除了第一次測驗分數爲7分,第二次測驗分數爲8分,中期分數爲90分以及最終分數爲80分時,除了總分爲81.25%之外,其他所有內容都可以,但是會顯示.8125並自動給學生F.我不知道如何修復它....需要關於java分級程序的幫助嗎?我需要製作一個程序,讀取學生總成績的百分比
import java.util.Scanner;
public class StudentClass {
// calculate grade first then the if else statements for the letter grade
public static Scanner grades = new Scanner (System.in);
public static double quiz1, quiz2, midterm, finalExam, Grades, totalGrade, bothQuizzes, PfinalExam, PmidTerm;
public static String studentname;
public static int Score;
public String getstudentname()
{
return studentname;
}
public double getquiz1()
{
return quiz1;
}
public double getquiz2()
{
return quiz2;
}
public double midterm()
{
return midterm;
}
public double finalExam()
{
return finalExam;
}
public void setquiz1 (double quiz1)
{
this.quiz1 = quiz1;
}
public void setquiz2 (double quiz2)
{
this.quiz2 = quiz2;
}
public void setmidterm()
{
this.midterm = midterm;
}
public void setfinalExam()
{
this.finalExam = finalExam;
}
public void setGrades()
{
}
public String toString(){
return this.quiz1 + " " + this.quiz2 + " " + this.midterm + " " + this.finalExam;
}
public static void readInput(){
System.out.println("Please enter the grade you got for the first quiz: ");
quiz1 = grades.nextInt();
while (quiz1 <0 || quiz1>10)
{
System.out.println("Please enter a grade between zero and ten: ");
quiz1 = grades.nextInt();
}
System.out.println("Please enter the grade you got for the second quiz: ");
quiz2 = grades.nextInt();
while (quiz2 <0 || quiz2>10)
{
System.out.println("Please enter a grade between zero and ten: ");
quiz2 = grades.nextInt();
}
System.out.println("Please enter the grade you got on your midterm: ");
midterm = grades.nextInt();
while (midterm <0 || midterm>100)
{
System.out.println("Please enter a grade between 0 and 100: ");
midterm = grades.nextInt();
}
System.out.println("Please enter the grade you got on your final exam: ");
finalExam = grades.nextInt();
while (finalExam < 0 || finalExam > 100)
{
System.out.println("Please enter a grade between 0 and 100: ");
finalExam = grades.nextInt();
}
}
public static void output()
{
System.out.println(" your score for the first quiz was " + quiz1);
System.out.println("your score for the second quiz was " + quiz2);
System.out.println(" your score for the midterm was " + midterm);
System.out.println("your score for the final exam was " + finalExam);
bothQuizzes = ((quiz1 + quiz2)/20)*.25;
PmidTerm = (midterm/100) *.25;
PfinalExam = (finalExam/100) * .50;
totalGrade = bothQuizzes + PmidTerm + PfinalExam;
System.out.println("Your total grade for these grades is " + totalGrade);
double letterGrade = totalGrade;
if (letterGrade >= 90)
{
System.out.println("Your grade is an A");
// grade = "A";
}
else if (letterGrade >= 80)
{
System.out.println("Your grade is a B");
}
else if (letterGrade >= 70)
{
System.out.println("Your grade is a C");
}
else if (letterGrade >= 60)
{
System.out.println("Your grade is a D");
}
else
{
System.out.println("Your grade is an F");
}
}
}
我認爲人們看你的標題,看到第一個兩句話,缺乏資本化,並下調投票你的問題認爲你要求的代碼,並沒有花時間來正確地格式化你的問題。您可能想要編輯它。 – DoubleDouble
是的,我就像爲什麼我得到像一百萬倒票?我並沒有乞求人們尋找類似這裏數百萬人的代碼,我只是需要幫助。 – Madridista94