Essay Class Design an Essay class that extends the GradedActivity(Shown below) c
ID: 3821350 • Letter: E
Question
Essay Class Design an Essay class that extends the GradedActivity(Shown below) 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: Grammar: 30 points Spelling: 20 points Correct length: 20 points Content: 30 points Demonstrate the class in a simple program.
//GradedActivity Class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package essaydemo;
/**
A class that holds a grade for a graded activity.
*/
public class GradedActivity
{
private double score; // Numeric score
/**
The setScore method sets the score field.
@param s The value to store in score.
*/
public void setScore(double s)
{
score = s;
}
/**
The getScore method returns the score.
@return The value stored in the score field.
*/
public double getScore()
{
return score;
}
/**
The getGrade method returns a letter grade
determined from the score field.
@return The letter grade.
*/
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;
}
}
Explanation / Answer
// Essay.java
package essaydemo;
public class Essay extends GradedActivity{
public Essay() {
}
public Essay(int grammerScore, int spellingScore, int lengthScore, int contentScore) {
this.grammerScore = grammerScore;
this.spellingScore = spellingScore;
this.lengthScore = lengthScore;
this.contentScore = contentScore;
setScore(grammerScore + spellingScore+lengthScore+contentScore);
}
private int grammerScore;
private int spellingScore;
private int lengthScore;
private int contentScore;
public int getGrammerScore() {
return grammerScore;
}
public void setGrammerScore(int grammerScore) {
this.grammerScore = grammerScore;
}
public int getSpellingScore() {
return spellingScore;
}
public void setSpellingScore(int spellingScore) {
this.spellingScore = spellingScore;
}
public int getLengthScore() {
return lengthScore;
}
public void setLengthScore(int lengthScore) {
this.lengthScore = lengthScore;
}
public int getContentScore() {
return contentScore;
}
public void setContentScore(int contentScore) {
this.contentScore = contentScore;
}
}
--------------------------------
TestEssay.java
package essaydemo;
public class TestEssay {
public static void main(String[] args)
{
Essay essay = new Essay(29, 16, 18, 26);
System.out.println("Grade is : " + essay.getGrade());
}
}
Sample run
java essaydemo.TestEssay
Grade is : B
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.