Bettsie Johnson
asked on
Java: Grade Activity with Inheritance
Hello Experts at Experts Exchange:
I'm working on an assignment that I need clarification and help upon. The constriction is that there is no constructor in the superclass, and the super-class cannot be modified. The Assignment is supposed to output something similar to following below. The first two questions asked can change because they are based on user input:
How many Essay questions are in the course? 10
How many Essay questions did the student miss? 4
Each question counts 10.0points.
The Grammer Score: 18.0
The Spelling Score: 12.0
The Correct Length Score: 12.0
The Content Score: 18.0
The exam score is 60.0
The exam grade is D
The constriction is that there is no constructor in the super class, and the super-class cannot be modified. The problem that I am currently having is setting up the arithmetic value(s) to provide accurate result.
Here is the code so far:
-Base Class-
The driver and sub class is below
DriverClass.javaEssay.java
I'm working on an assignment that I need clarification and help upon. The constriction is that there is no constructor in the superclass, and the super-class cannot be modified. The Assignment is supposed to output something similar to following below. The first two questions asked can change because they are based on user input:
How many Essay questions are in the course? 10
How many Essay questions did the student miss? 4
Each question counts 10.0points.
The Grammer Score: 18.0
The Spelling Score: 12.0
The Correct Length Score: 12.0
The Content Score: 18.0
The exam score is 60.0
The exam grade is D
The constriction is that there is no constructor in the super class, and the super-class cannot be modified. The problem that I am currently having is setting up the arithmetic value(s) to provide accurate result.
Here is the code so far:
-Base Class-
public class GradeActivity
{
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;
}
}
The driver and sub class is below
DriverClass.javaEssay.java
ASKER
Hi Jans,
I have found this thread now but the updated one is here:
https://www.experts-exchange.com/questions/29119657/Showing-Graded-variable-with-Inheritance.html
I am having issue with the grade set to 0 always instead of being based on the total grade of numericScore. I have also taken your suggestion and have changed the arithmetic for the others. Those work well but there is issue with numericScore not showing proper grade.
I have found this thread now but the updated one is here:
https://www.experts-exchange.com/questions/29119657/Showing-Graded-variable-with-Inheritance.html
I am having issue with the grade set to 0 always instead of being based on the total grade of numericScore. I have also taken your suggestion and have changed the arithmetic for the others. Those work well but there is issue with numericScore not showing proper grade.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
From there, you need to split up your numericScore into the 4 separate sections (grammar, spelling, length, content).
It looks like each of those already has a percentage value (grammarScore, etc).
Just multiply the numericScore by the percentage. (Make sure to make the percentage an actual percentage value by diving by 100: So, 30 would be 30 / 100)