java 扩展似乎未发生

rvpgvaaj  于 2023-04-19  发布在  Java
关注(0)|答案(1)|浏览(157)

作为我课堂作业的一部分,我必须把我课本上的代码复制到jgrasp中。
我刚刚复制完最新的作业,我检查了一下,我复制得很完美,下面的代码。但是当我试图编译它时,我得到了下面的错误。

FinalExam.java:30: error: cannot find symbol
      setScore(numericScore); 
      ^
  symbol:   method setScore(double)
  location: class FinalExam
1 error

我在GradedActivity类中编写了setScore方法,所以FinalExam类应该继承了它,我能想到的解释错误的唯一想法是它由于某种原因没有继承?有人有想法或建议为什么它不工作吗?

public class GradedActivity
{
   private double score;
   
   public GradedActivity()
   {
      score = 0.0;
   }
   
   private void setScore(double s)
   {
      score = s;
   }
   
   public double getScore()
   {
      return score;
   }
   
   public char getGrade()
   {
      char letterGrade;
      
      if (score >= 90)
         {
            letterGrade = 'A';
         }
      else if (score >= 80)
         {
            letterGrade = 'B';
         }
      else if (score >= 70)
         {
            letterGrade = 'C';
         }
      else if (score >= 60)
         {
            letterGrade = 'D';
         }
      else
         {
            letterGrade = 'F';
         }
         
      return letterGrade;
   }
}
/**   
   This class determines the grade for a final exam.   
*/
public class FinalExam extends GradedActivity
{
   private int numQuestions;  // Number of questions
   private int numMissed;     // Questions missed
   
   public FinalExam(int questions, int missed)
   {
      double numericScore;
      
      numQuestions = questions;
      numMissed = missed;
      
      numericScore = 100.0 - (missed * getPointsEach());
      
      // Call the inherited setScore method to   
      // set the numeric score.
      setScore(numericScore); 
   }
   
   public int getNumQuestions()
   {
      return numQuestions;
   }
   
   public int getNumMissed()
   {
      return numMissed;
   }
   
   public double getPointsEach()
   {
      return 100.0 / numQuestions;
   }
}
aiazj4mn

aiazj4mn1#

private函数继承,更改

private void setScore(double s)

protected void setScore(double s)

相关问题