Question
class GradedActivity { private double score; public void setScore(double s) { this.score = s; } public double getScore() { return this.score; } public char getGrade()
class GradedActivity {
private double score;
public void setScore(double s) {
this.score = s;
}
public double getScore() {
return this.score;
}
public char getGrade() {
if (this.score >= 90) {
return 'A';
} else if (this.score >= 80) {
return 'B';
} else if (this.score >= 70) {
return 'C';
} else if (this.score >= 60) {
return 'D';
} else {
return 'F';
}
}
}
class PassFailActivity extends GradedActivity {
protected double minPassingScore;
PassFailActivity(double mps) {
this.minPassingScore = mps;
}
public char getGrade() {
double score = getScore();
if (score >= minPassingScore) {
return 'P';
} else {
return 'F';
}
}
}
class PassFailExam extends PassFailActivity {
private int numQuestions;
private double pointsEach;
private int numMissed;
PassFailExam(int questions, int missed, double minPassing) {
super(minPassing);
this.numQuestions = questions;
this.numMissed = missed;
}
public double getPointsEach() {
return this.pointsEach;
}
public int getNumMissed() {
return this.numMissed;
}
void calculatePoints() {
this.pointsEach = 100.0 / this.numQuestions;
double score = 100 - (this.numMissed * this.pointsEach);
setScore(score);
}
}
public class Main
{
public static void main(String[] args) {
PassFailExam obj = new PassFailExam(100, 20, 55.0);
obj.calculatePoints();
System.out.println("Pass/Fail status: " + obj.getGrade());
System.out.println("Student's score: " + obj.getScore());
}
}
Tutorial QUESTIONS From the UML class diagram, answer the following questions: 1. How many superclass and subclass could be derived? List them. 2. How the abstract classes able to be conducted? What are the situations to be considered? Explain 3. How the polymorphism able to be conducted? What are the situations to be considered? Explain 4. How the interface able to be conducted? What are the situations to be considered? Explain. 5. In writing a code program, is it possible to apply abstract classes and interface? Explain 6. In writing a code program, is it possible to apply abstract classes and polymorphism? Explain Kuala Lumpur Tutorial Consider the following UML Class diagram: GradedActivity This class holds a grade for a graded activity - score : double + setScore (3: double): void + getScore(): double + getGrade(): char Pass FailActivity - minpassingScore : double This class holds numeric score and determines whether the score is passing or failing + Pass FailActivity (mp3: double) + getGrade(): char Pass FailExam This class determines a passing or failing grade for an exam - numQuestions : int - pointsEach : double > Comparable - numMissed : int + equals (g: GradedActivity) + Pass FailExam (questions: int, missed: int, minpassing: double) + getPointsEach(): double + getNumMissed(): int + calculatePoints(): void :boolean
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started