Java programming Essay class Desgin an Essay class that exte

Java programming:

Essay class:

Desgin 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:

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

Demonstrate the class in a simple program.

*GradedActivity*

/**
   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;

}

}

Solution

public class Essay extends GradedActivity {

double grammerMarks;
double spellingMarks;
double correctLenthMarks;
double contentMarks;

public Essay(double grammerMarks, double spellingMarks, double correctLenthMarks, double contentMarks) {
this.contentMarks = contentMarks;
this.correctLenthMarks = correctLenthMarks;
this.grammerMarks = grammerMarks;
this.spellingMarks = spellingMarks;
}

public double calculateScore() {
return (this.contentMarks + this.correctLenthMarks + this.grammerMarks + this.spellingMarks);
}

public static void main(String[] args) {
Essay es = new Essay(20, 20, 10, 20);
es.setScore(es.calculateScore());
System.out.println(es.getGrade());
}

}

Java programming: Essay class: Desgin an Essay class that extends the GradedActivity* class presented in this chapter. The Essay class should determine the grad
Java programming: Essay class: Desgin an Essay class that extends the GradedActivity* class presented in this chapter. The Essay class should determine the grad

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site