You will create an Essay class that inherits from the GradedActivity class. The Essay class should determine the grade a student receives on an essay. The essay score can be up to 100 points and is determined by the following: Grammar: Spelling: Correct Length: Content: You do not need to do any verification of the number of points. All you will do in the Essay class is to add up the four points and send it to GradedActivity. Start with the program GradedActivity.java. You could modify FinalExam.java Naming: Name the Java project: LastFProjectAssign08 Name the driver program (main): LastFAssign08.java Where Last is your last name and F is the first initial of your first name. Ex: OgleD Call the essay class: Essay.java. Make sure you name, class, and date are comments in this file. Save in a file folder on your storage device. Sample output: What was the grammar score on the essay? 15 What was the spelling score on the essay? 10 What was the length score on the essay? 10 What was the content score on the essay? 50 The essay score is 85.0 The essay grade is B (((BELOW IS PROGRAM GRADEDACTIVITY.JAVA))) ** * A class that holds a grade for a graded activity. */ public class GradedActivity { private double score; // Numeric score /** * The setScore method stores its argument in * the score field. */ public void setScore(double s) { score = s; } /** * The getScore method returns the score field. */ public double getScore() { return score; } /** * The getGrade method returns a letter grade * determined from the score field. */ public char getGrade() { char letterGrade; // To hold the grade 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; } } (((BELOW IS PROGRAM FILEEXAM.JAVA))) /** * This class determines the grade for a final exam. */ public class FinalExam extends GradedActivity { private int numQuestions; // Number of questions private double pointsEach; // Points for each question private int numMissed; // Number of questions missed /** * The constructor accepts as arguments the number * of questions on the exam and the number of * questions the student missed. */ public FinalExam(int questions, int missed) { double numericScore; // To calculate the numeric score // Set the numQuestions and numMissed fields. numQuestions = questions; numMissed = missed; // Calculate the points for each question and // the numeric score for this exam. pointsEach = 100.0 / questions; numericScore = 100.0 - (missed * pointsEach); // Call the superclass's setScore method to // set the numeric score. setScore(numericScore); } /** * The getPointsEach method returns the pointsEach * field. */ public double getPointsEach() { return pointsEach; } /** * The getNumMissed method returns the numMissed * field.*/ public int getNumMissed() { return numMissed; } }
You will create an Essay class that inherits from the GradedActivity class. The Essay class should determine the grade a student receives on an essay. The essay score can be up to 100 points and is determined by the following:
- Grammar:
- Spelling:
- Correct Length:
- Content:
- You do not need to do any verification of the number of points.
- All you will do in the Essay class is to add up the four points and send it to GradedActivity.
Start with the program GradedActivity.java. You could modify FinalExam.java
Naming:
- Name the Java project: LastFProjectAssign08
- Name the driver program (main): LastFAssign08.java
- Where Last is your last name and F is the first initial of your first name. Ex: OgleD
- Call the essay class: Essay.java. Make sure you name, class, and date are comments in this file.
- Save in a file folder on your storage device.
Sample output:
What was the grammar score on the essay? 15
What was the spelling score on the essay? 10
What was the length score on the essay? 10
What was the content score on the essay? 50
The essay score is 85.0
The essay grade is B
(((BELOW IS PROGRAM GRADEDACTIVITY.JAVA)))
** * A class that holds a grade for a graded activity.
*/
public class GradedActivity
{
private double score; // Numeric score
/** * The setScore method stores its argument in
* the score field. */
public void setScore(double s)
{
score = s;
}
/** * The getScore method returns the score field. */
public double getScore()
{
return score;
}
/** * The getGrade method returns a letter grade
* determined from the score field. */
public char getGrade()
{
char letterGrade; // To hold the grade
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;
}
}
(((BELOW IS PROGRAM FILEEXAM.JAVA)))
/** * This class determines the grade for a final exam.
*/
public class FinalExam extends GradedActivity
{
private int numQuestions; // Number of questions
private double pointsEach; // Points for each question
private int numMissed; // Number of questions missed
/** * The constructor accepts as arguments the number
* of questions on the exam and the number of
* questions the student missed.
*/
public FinalExam(int questions, int missed)
{
double numericScore; // To calculate the numeric score
// Set the numQuestions and numMissed fields.
numQuestions = questions;
numMissed = missed;
// Calculate the points for each question and
// the numeric score for this exam.
pointsEach = 100.0 / questions;
numericScore = 100.0 - (missed * pointsEach);
// Call the superclass's setScore method to
// set the numeric score.
setScore(numericScore);
}
/** * The getPointsEach method returns the pointsEach
* field.
*/
public double getPointsEach()
{
return pointsEach;
}
/**
* The getNumMissed method returns the numMissed
* field.*/
public int getNumMissed()
{
return numMissed;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images