Design an Essay class that is derived from the GradedActivity class presented in this chapter. The Essay class should determine the grade a student receives on 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

Respuesta :

Answer:

Consider the code below

Explanation:

Please find the below GradedActivity, Essay and EssayDemo class.

Also find the sample output.

Please revert back in case anything needs to change.

****** GradedActivity Class *******

public class GradedActivity {

private int score;

private String grade;

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

public String getGrade() {

if (score >=90 && score<=100) {

grade = "A";

} else if (score >=80 && score<=89) {

grade = "B";

} else if (score >=70 && score<=79) {

grade = "C";

} else if (score >=60 && score<=69) {

grade = "D";

} else {

grade = "F";

}

return grade;

}

}

****** Essay Class *******

public class Essay extends GradedActivity {

private int grammer;

private int spelling;

private int correctLength;

private int content;

public int getGrammer() {

return grammer;

}

public int getSpelling() {

return spelling;

}

public int getCorrectLength() {

return correctLength;

}

public int getContent() {

return content;

}

private void setGrammer(int grammer) {

if(grammer >=0 && grammer <=30)

this.grammer = grammer;

else

this.grammer = 0;

}

private void setSpelling(int spelling) {

if(spelling >=0 && spelling <=20)

this.spelling = spelling;

else

this.spelling = 0;

}

private void setCorrectLength(int correctLength) {

if(correctLength >=0 && correctLength <=20)

this.correctLength = correctLength;

else

this.correctLength = 0;

}

private void setContent(int content) {

if(content >=0 && content <=30)

this.content = content;

else

this.content = 0;

}

public void setScore(int grammer,int spelling, int correctLength, int content) {

setGrammer(grammer);

setSpelling(spelling);

setCorrectLength(correctLength);

setContent(content);

super.setScore(getGrammer() + getSpelling() + getCorrectLength() + getContent());

}

public int getScore() {

return super.getScore();

}

}

***** EssayDemo Class *****

public class EssayDemo {

public static void main(String[] args) {

Essay essay = new Essay();

essay.setScore(25,18,20,25);

System.out.println("Grammar: "+essay.getGrammer());

System.out.println("Spelling: "+essay.getSpelling());

System.out.println("Correct Length: "+essay.getCorrectLength());

System.out.println("Content: "+essay.getContent());

System.out.println("Total Score: "+essay.getScore());

System.out.println("Grade: "+essay.getGrade());

}

}

Ver imagen cancinodavidq
ACCESS MORE