Question
Create a UML diagram (No Code only Uml Diagram) of the Graded Activity superclass, with the following subclasses: Curved Activity, FinalExam, PassFailActivity, and its subclass,
Create a UML diagram (No Code only Uml Diagram) of the Graded Activity superclass, with the following subclasses: Curved Activity, FinalExam, PassFailActivity, and its subclass, PassFailExam. Show all instance variables, and all methods in each class and subclass of the hierarchy. Highlight the overridden methods, and underline the overloaded methods.
public class FinalExamDemo { public static void main(String[] args) { String input; // To hold input int questions; // Number of questions int missed; // Number of questions missed
// Get the number of questions on the exam. input = JOptionPane.showInputDialog("How many " + "questions are on the final exam?"); questions = Integer.parseInt(input);
// Get the number of questions the student missed. input = JOptionPane.showInputDialog("How many " + "questions did the student miss?"); missed = Integer.parseInt(input);
// Create a FinalExam object. FinalExam exam = new FinalExam(questions, missed);
// Display the test results. JOptionPane.showMessageDialog(null, "Each question counts " + exam.getPointsEach() + " points. The exam score is " + exam.getScore() + " The exam grade is " + exam.getGrade()); System.out.println(exam);
System.exit(0);
} }
public double getScore() { return score; }
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; } public String toString() { return(" Graded Activity Score: " + score + "\t" + "Letter Grade: " + getGrade()); } }
public PassFailActivity(double mps) { minPassingScore = mps; }
public char getGrade() { char letterGrade;
if (super.getScore() >= minPassingScore) letterGrade = 'P'; else letterGrade = 'F';
return letterGrade; } public String toString() { return(" Pass Fail Activity Score: " + getScore() + "\t" + "Passing Grade: " + getGrade()); } }
public class PassFailExam extends PassFailActivity { private int numQuestions; // Number of questions private double pointsEach; // Points for each question private int numMissed; // Number of questions missed
public PassFailExam(int questions, int missed, double minPassing) { // Call the superclass constructor. super(minPassing);
// Declare a local variable for the score. double numericScore;
// 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); }
public double getPointsEach() { return pointsEach; }
public int getNumMissed() { return numMissed; } public String toString() { return(" Pass Fail Exam Points each: " + getPointsEach() + "\t" + "Score: " + getScore()+ "\t" + "Passing Grade: " + getGrade()); } }
public class PassFailExamDemo { public static void main(String[] args) { int questions; // Number of questions int missed; // Number of questions missed double minPassing; // Minimum passing score
// Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in);
// Get the number of questions on the exam. System.out.print("How many questions are " + "on the exam? "); questions = keyboard.nextInt();
// Get the number of questions missed. System.out.print("How many questions did " + "the student miss? "); missed = keyboard.nextInt();
// Get the minimum passing score. System.out.print("What is the minimum " + "passing score? "); minPassing = keyboard.nextDouble();
// Create a PassFailExam object. PassFailExam exam = new PassFailExam(questions, missed, minPassing);
// Display the points for each question. System.out.println("Each question counts " + exam.getPointsEach() + " points.");
// Display the exam score. System.out.println("The exam score is " + exam.getScore());
// Display the exam grade. System.out.println("The exam grade is " + exam.getGrade()); System.out.println(exam); } }
public class PolymorphismExample {
public static void main(String args[]) {
GradedActivity[] myActivities = new GradedActivity[5]; GradedActivity myGradedActivity = new GradedActivity(); myGradedActivity.setScore(70.0); myActivities[0]= myGradedActivity; GradedActivity myPassFailActivity = new PassFailActivity(70); myPassFailActivity.setScore(70); myActivities[1] = myPassFailActivity; GradedActivity myPassFailExam = new PassFailExam(10, 3, 70); myActivities[2] = myPassFailExam; GradedActivity myFinalExam = new FinalExam(10, 3); myActivities[3] = myFinalExam; GradedActivity myCurvedActivity = new CurvedActivity(1.20); myCurvedActivity.setScore(60); myActivities[4] = myCurvedActivity; //Polymorphism at work! for (int i=0; i < myActivities.length; i++) { System.out.println(myActivities[i]); }
} }
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