Question: code in Java /* =========== TO DO for your participant activity ====================== 1. complete the GradedActivity class as we've been discussed in class - review
code in Java
/* =========== TO DO for your participant activity ====================== 1. complete the GradedActivity class as we've been discussed in class - review the recorded lecture for those details - make sure to give detailed document 2. create a derived class for exams or assignments 3. Update the driver to test each and every functionality in every class 4. Optional: enhance the Quiz class to include the questions, the max point for each question, and the correponding actual point earned. =========================================================================*/ /** attr: + score + maxScore + weight + title functionalities: + constructor + all getters + setScore + calcPercent + calcWeight + toString */ class GradedActivity{ //attributes private double score; private double maxScore; private double weight; private String title; //constructor public GradedActivity(String title, double weight, double maxScore){ this.title = title; this.maxScore = maxScore; this.weight = weight; this.score = 0; }
//calculate the percentage of this earned grade public double calcPercent(){ return (this.score / this.maxScore) * 100; } //set the score public void setScore(double score){ this.score = score; } public String toString(){ return "Title:" + this.title + " Weight: " + this.weight + " Max Score: " + this.maxScore + " Score:" + this.score; } }
/* class represents a quiz + time limit + number of questions */ class Quiz extends GradedActivity { private int timeLimit; //in minutes private int numQuestion; public Quiz(String title, double weight, double maxScore, int time, int nq){ super(title, weight, maxScore); this.timeLimit = time; this.numQuestion = nq; } public String toString(){ return super.toString() + " Time limit: " + this.timeLimit + " Number of Questions: " + this.numQuestion; } }
//Driver to test the above classes public class Grade { public static void main(String[] args){ //testing the graded activity GradedActivity ga1 = new GradedActivity("Test 1", 0.1, 100.0); System.out.println(ga1); ga1.setScore(90.0); System.out.println("Percentage: " + ga1.calcPercent() + " "); //testing the derive quiz class Quiz q = new Quiz("Quiz 1", 0.2, 40.0, 20, 15); System.out.println(q); q.setScore(25.0); System.out.println("Percentage: " + q.calcPercent() + " "); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
