作業問題作業:類記錄學生成績
寫分級程序使用以下分級策略的類: 一)3個測驗分級滿分爲10分,加權25% b)中1期中分數爲100分,加權爲35% c)100分中的1分爲最終分數,加權40% 您的課程需要一套存取器和增變器方法,完整構造函數,默認構造函數,equals方法和一個String方法。該類應該僅包含測驗,中期和末期的實例變量。 然後,編寫一個測試程序,讀取學生的分數並輸出學生的分數和學生的記錄。以及學生整個課程和最終字母等級的整體數字分數。
無論我做什麼,我都會收到錯誤!所有的錯誤都是「錯誤:無法找到符號」如果有人能幫我弄清楚什麼是錯誤的,我會很高興。我花了幾個小時。
這是我的方法...
import java.util.Scanner;
public class StudentRecord
{
/***DECLARATIONS**/
private int quizScore1;
private int quizScore2;
private int quizScore3;
private int midtermScore;
private int finalScore;
/***ACCESSOR METHODS**/
public int getQuizScore()
{
return quizScore1;
return quizScore2;
return quizScore3;
}
public int getMidtermScore()
{
return midtermScore;
}
public int getFinalScore()
{
return finalScore;
}
/***MUTATOR METHODS**/
public void setQuizScore(int quizScore1, int quizScore2, int quizScore3)
{
if (quizScore1 < 0 || quizScore1 > 10)
{
System.out.println("Error: Invalid Quiz Grade");
}
if (quizScore2 < 0 || quizScore2 > 10)
{
System.out.println("Error: Invalid Quiz Grade");
}
if (quizScore3 <0 || quizScore3 > 10)
{
System.out.println("Error: Invalid Quiz Grade");
}
else
{
this.quizScore1 = quizScore1;
this.quizScore2 = quizScore2;
this.quizScore3 = quizScore3;
}
}
public void setMidtermScore(int midtermScore)
{
if (midtermScore < 0 || midtermScore > 100)
{
System.out.println("Error: Invalid Midterm Score");
}
else
{
this.midtermScore = midtermScore;
}
}
public void setFinalScore(int finalScore)
{
if (finalScore < 0 || finalScore > 100)
{
System.out.println("Error: Invalid Final Score");
}
else
{
this.finalScore = finalScore;
}
}
/***OTHER METHODS***/
public void studentRecord()
{
quizScore1 = 0;
quizScore2 = 0;
quizScore3 = 0;
midtermScore = 0;
finalScore = 0;
}
public void studentRecord(int quizScore1, int quizScore2, int quizScore3, int midtermScore, int finalScore)
{
System.out.println("Quiz Score 1: " + quizScore1);
System.out.println("Quiz Score 2: " + quizScore2);
System.out.println("Quiz Score 3: " + quizScore3);
System.out.println("Midterm Score: " + midtermScore);
System.out.println("Final Score: " + finalScore);
}
public boolean equals (StudentRecord otherStudentRecord)
{
return (quizScore1 == otherStudentRecord.quizScore1);
return (quizScore2 == otherStudentRecord.quizScore2);
return (quizScore3 == otherStudentRecord.quizScore3) ;
return (midtermScore == otherStudentRecord.midtermScore);
return (finalScore == otherStudentRecord.finalScore);
}
public int getGradeScore()
{
int gradeScore;
gradeScore = (((quizScore1 + quizScore2 + quizScore3)/3)/10 * 25) + (midtermScore/100 * 35) + (finalScore/100 * 40);
}
public char getLetterGrade()
{
int gradeScore;
char letterGrade;
if (gradeScore >= 90 && gradeScore <= 100)
{
return 'A';
}
else if (gradeScore >= 80 && gradeScore <= 89)
{
return 'B';
}
else if (gradeScore >= 70 && gradeScore <= 79)
{
return 'C';
}
else if (gradeScore >= 60 && gradeScore <= 69)
{
return 'D';
}
else
{
return 'F';
}
}
public String toString()
{
return ("Grade Score is " + gradeScore + "and letter grade is " + letterGrade);
}
}
...這是我的測試程序...
import java.util.Scanner;
public class CalculatingStudentGrade
{
public static void main(String[] args)
{
Scanner keyboard;
int quizScore1, quizScore2, quizScore3, midtermScore, finalScore;
keyboard = new Scanner(System.in);
System.out.println("Enter Quiz 1 score:");
quizScore1 = keyboard.nextInt();
System.out.println("Enter Quiz 2 score:");
quizScore2 = keyboard.nextInt();
System.out.println("Enter Quiz 3 score:");
quizScore3 = keyboard.nextInt();
StudentRecord.getQuizScore();
StudentRecord.getMidtermScore();
StudentRecord.getFinalScore();
StudentRecord.setQuizScore();
StudentRecord.setMidtermScore();
StudentRecord.setFinalScore();
StudentRecord.StudentRecord();
StudentRecord.getGradeScore();
StudentRecord.getLetterGrade();
}
}
'StudentRecord.getQuizScore();'和你的其他電話將無法工作。你需要一個StudentRecord的實例。請做'StudentRecord studentRecord = new StudentRecord();'然後'studentRecord.getQuizScore();'。 – 2015-04-01 06:17:05
Btw。這段代碼有太多的錯誤,我不知道該從哪裏開始幫助你。也許你應該閱讀一兩個教程,然後你應該看到錯誤。 https://docs.oracle.com/javase/tutorial/java/javaOO/classes.html – 2015-04-01 06:26:50
即使這給了我一個錯誤:( – 2015-04-01 06:27:35