Extends Seems to not be occuring

37 Views Asked by At

As part of my assignment for my class I'm have to maunally copy code from my text book into jgrasp.

I just finished copying the latest assignment, and I checked that I copied it perfectly, code down below. But when I try to compile it I get the following error.

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

I wrote the setScore method in the GradedActivity class so the FinalExam class should have inherited it, the only idea I can think of to explain the error is that it didn't inherit for some reason? Does anyone have an idea or suggestion for why it isn't working?

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;
   }
}
1

There are 1 best solutions below

1
Elliott Frisch On

private functions are not inherited. Change

private void setScore(double s)

to

protected void setScore(double s)