Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design an Essay class that extends the GradedActivity class presented in this ch

ID: 3695801 • Letter: D

Question

Design an Essay class that extends the GradedActivity class presented in this chapter. The Essay class should determine the grade a student receives for an essay. The student's essay score can be up to 100 and is determined in the following manner: Grammer: up to 30 points, Spelling: up to 20 points, Correct length: up to 20 points, Content: up to 30 points. Once you have designed the class, design a program that prompts the user to enter the number of points that a student has earned for grammar, spelling, length, and content. Create an Essay object and store this data in the object. Use the object's methods to get the student's overall score and grade, and dispaly this data on the screen.

Explanation / Answer

########################################################

public class GraddedActivity {
  
   private double score;
  
   public void setScore(double score){
       this.score = score;
   }
  
   public double getScore(){
       return score;
   }
  
   public String getGrade(){
      
       if(score >= 90)
           return "A";
       else if(score >=80)
           return "B";
       else if(score >= 70)
           return "C";
       else if(score >= 60)
           return "D";
       else
           return "F";
   }

}

########################################################

class Essay extends GraddedActivity{
   private double grammar;
   private double spelling;
   private double length;
   private double content;
  
   public Essay() {
       grammar = 0;
       spelling = 0;
       length = 0;
       content = 0;
   }

   /**
   * @param grammar
   * @param spelling
   * @param length
   * @param content
   */
   public Essay(double grammar, double spelling, double length, double content) {
       this.grammar = grammar;
       this.spelling = spelling;
       this.length = length;
       this.content = content;
   }

   /**
   * @return the grammar
   */
   public double getGrammar() {
       return grammar;
   }

   /**
   * @return the spelling
   */
   public double getSpelling() {
       return spelling;
   }

   /**
   * @return the length
   */
   public double getLength() {
       return length;
   }

   /**
   * @return the content
   */
   public double getContent() {
       return content;
   }

   /**
   * @param grammar the grammar to set
   */
   public void setGrammar(double grammar) {
       this.grammar = grammar;
   }

   /**
   * @param spelling the spelling to set
   */
   public void setSpelling(double spelling) {
       this.spelling = spelling;
   }

   /**
   * @param length the length to set
   */
   public void setLength(double length) {
       this.length = length;
   }

   /**
   * @param content the content to set
   */
   public void setContent(double content) {
       this.content = content;
   }
  
   public double getTotalScore(){
       // calling parents methods
       setScore(grammar+spelling+content+length);
       return getScore();
   }
  
   @Override
   public String toString() {
       return "Grammer: "+grammar+
       " Content: "+content+
       " Length: "+length+
       " Spelling: "+spelling+
       " Total Score: "+getTotalScore()+
       " Grade: "+getGrade();
   }
  
}

####################################################################

Test Class:

public class TestEssayClass {
  
   public static void main(String[] args) {
      
       Essay essay = new Essay();
      
       essay.setGrammar(25);
       essay.setLength(18);
       essay.setSpelling(16);
       essay.setContent(27);
      
       System.out.println(essay.toString());
      
   }

}

##################################################

output:

Grammer: 25.0
Content: 27.0
Length: 18.0
Spelling: 16.0
Total Score: 86.0
Grade: B

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote