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

\\ Essay Class Design an Essay class that extends the GradedActivity class prese

ID: 3760971 • Letter: #

Question

Essay Class

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 cna be up to 100 and is determinded in the following manner:

Grammar: 30 points
Spelling 20 Points
Correct length: 20 points
Content: 30 points

Demonstrate the class in a simple program.

Homwork

-Create a Essay Demo class that does the following:
Create an Essay object using the default constructor.
Assign scores to the object:
grammer = 25pts, spelling = 18 pts, length = 20 pts content = 25 pts


The output should display the score details mentioned above along with the totlal points and letter grade, whereby 90-100 = A, 80 - 89 = B, 70 - 79 = C, 60 -69 = D, <60 = F

-Create a GradedActivity class with the following methods:
setScore,getScore,getGrade

-Create a derived class of GradedActivity called Essay with the following methods:

setScore - sets points for grammer, spelling, length, and content
This method also overloads the super class method.

Make the following 4 methods private:
setGrammer - sets the grammar points, validating them before they are set
setSpelling - sets the spelling points, validating them before they are set
setCorrectLength - sets the points for correct length, validating them before they are set
setContent - sets the points for content, validating them before they are set
Make the following 4 methods public:
getGrammar,getSpelling,getCorrectLength,getContent,getScore

Explanation / Answer

Dear...

import java.util.Scanner;

public class GradedActivity
{
private double score;

public 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;
}
}
public class Essay extends GradedActivity
{
private double grammar;
private double spelling;
private double correctLength;
private double content;

public void setScore(double gr, double sp, double len, double cnt)
{
setGrammar(gr);
setSpelling(sp);
setCorrectLength(len);
setContent(cnt);
super.setScore(grammar + spelling + correctLength + content);
}

private void setGrammar(double g)
{
if (g <= 30.0)
grammar = g;
else
grammar = 0.0;
}
private void setSpelling(double s)
{
if (s <= 20.0)
spelling = s;
else
spelling = 0.0;
}

private void setCorrectLength(double c)
{
if (c <= 20.0)
correctLength = c;
else
correctLength = 0.0;
}
private void setContent(double c)
{
if (c <= 30)
content = c;
else
content = 0.0;
}
public double getGrammar()
{
return grammar;
}
public double getSpelling()
{
return spelling;
}
public double getCorrectLength()
{
return correctLength;
}

public double getContent()
{
return content;
}
public double getScore()
{
return grammar + spelling + correctLength + content;
}
}

public class FinalExam extends GradedActivity

{
private int numQuestions;
private double pointsEach;
private int numMissed;

public FinalExam(int questions, int missed)
{
double numericScore;

numQuestions = questions;
numMissed = missed;

pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);

setScore(numericScore);
}

public double getPointsEach()
{
return pointsEach;
}

public int getNumMissed()
{
return numMissed;
}
}

public class PassFailActivity extends GradedActivity
{
private double minPassingScore;

public PassFailActivity(double mps)
{
minPassingScore = mps;
}

public char getGrade()
{
char letterGrade;

if (super.getScore() >= minPassingScore)
letterGrade = 'P';
else
letterGrade = 'F';

return letterGrade;
}
}
public class PassFailExam extends PassFailActivity
{
private int numQuestions;
private double pointsEach;
private int numMissed;


public PassFailExam(int questions, int missed, double minPassing)
{
super(minPassing);
double numericScore;
numQuestions = questions;
numMissed = missed;
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);
setScore(numericScore);
}
public double getPointsEach()
{
return pointsEach;
}
public int getNumMissed()
{
return numMissed;
}
}