2015-04-01 90 views
-3

作業問題作業:類記錄學生成績

寫分級程序使用以下分級策略的類: 一)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(); 
    } 
} 
+0

'StudentRecord.getQuizScore();'和你的其他電話將無法工作。你需要一個StudentRecord的實例。請做'StudentRecord studentRecord = new StudentRecord();'然後'studentRecord.getQuizScore();'。 – 2015-04-01 06:17:05

+0

Btw。這段代碼有太多的錯誤,我不知道該從哪裏開始幫助你。也許你應該閱讀一兩個教程,然後你應該看到錯誤。 https://docs.oracle.com/javase/tutorial/java/javaOO/classes.html – 2015-04-01 06:26:50

+0

即使這給了我一個錯誤:( – 2015-04-01 06:27:35

回答

0

您不能返回多個聲明這兒過得認爲這將是所有測驗的總和。所以把它加起來然後返回。

public int getQuizScore() 
    { 
     return quizScore1; 
     return quizScore2; 
     return quizScore3; 
    } 

代替

public int getQuizScore() 
{ 
    return quizScore1+quizScore2+quizScore3; 
} 
+0

那麼我將如何返回所有3個測驗分數呢?我必須得到QuizScore1,getQuizScore2和getQuizScore3? – 2015-04-01 06:12:07

+0

你想得分總和。rite ?? – Pratik 2015-04-01 06:13:54

+0

@JosephChang你必須定義一個返回值有三個屬性的對象,你必須返回這個 – Jens 2015-04-01 06:15:03

相關問題