Tasks - PassFailCourse Class • Task 1: The PassFailCourse class contains all the functionality of the Course class as it
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Tasks - PassFailCourse Class • Task 1: The PassFailCourse class contains all the functionality of the Course class as it
package assignment;
public class PassFailCourse extends Course { //See Assignment 3 or "High Level View of YourTasks" in Folio to see what Course contains /** * This overrides Course's computerCourseAveragemethod. * The course is Pass / Fail, which means youwill not receive a specific grade. * however, you need a 75% average to pass thecourse. * (Remember that the Student class hascomputeMyAverage as a method) * @return the number of students who's averageof all the student's quizzes is 75% or better divided by the totalstudents in the course */ @Override public double computeCourseAverage() { //counter for passingstudents double countP = 0; double pass = 75; //for loop to determine eachstudent's average is what letters grade //increase the count forthis for (int i = 0; i <getAllStudents().size(); i++) { //need tocall computeMyAverage method of the Student class double avg= getAllStudents().get(i).computeMyAverage(); //ifstatements increase counter for passing if student's average is ator above 75% if(avg>= pass) { countP++; } } //RETURN double passingStudents =(countP/getAllStudents().size()); return passingStudents; }}
Here is the course class because this class extendsCourse
package assignment;import java.util.ArrayList;public class Course { // member variable to store all students in acourse ArrayList<Student> students; // default constructor public Course() { students = newArrayList<Student>(); } /** * @return the allStudents */ public ArrayList<Student> getAllStudents(){ return students; } /** * @param allStudents the allStudents toset */ public void setAllStudents(ArrayList<Student>allStudents) { students = allStudents; } /** * * @param stu Student object * @return true if successfully added, falseotherwise */ public boolean addStudent(Student stu) { // if not valid if (stu == null) return true; // loop over all students and check ifalready exists for (Student student : students){ if(student.equals(stu)) returnfalse; } return students.add(stu); } /** * @desc removes a student if exists * @param stu Student object * @return true if already exists, falseotherwise */ public boolean removeStudent(Student stu) { // remove the student if valid andexists return students.remove(stu); } /** * @desc updates a student if it exists * @param stu * @return true if students exists and updatesuccessfull, * falseotherwise */ public boolean updateStudent(Student stu) { // if not valid if (stu == null) return false; // if list containts the student if (students.contains(stu)) { students.set(students.indexOf(stu), stu); return true; } return false; } /** * @return the average of all the student'squizzes */ public double computeCourseAverage() { double scoresAvgSum = 0.0; int totalScores = 0; for(int i =0;i<students.size();i++){ if(students.get(i) !=null) { Score[] studentScores =students.get(i).getAllMyScores(); for(int j = 0; j <studentScores.length; j++) { if(studentScores[j] !=null) { scoresAvgSum +=studentScores[j].getScoreValue(); totalScores++; } } } }
returnscoresAvgSum/totalScores; } public String getNumberOfStudents() { // TODO Auto-generated methodstub return null; }}
run with driver class provided.
package assignment;public class A4PassFailDriver {
public static void main(String[] args){ //NOTE: BELOW IS A STARTERSET OF TEST FOR YOUR ASSIGNMENT. //IT IS NOT THE ONLY SET OFTESTS YOU SHOULD DO FOR YOUR ASSIGNMENT! //Student Class Student stu1 = newStudent("Bugsy",521); stu1.AddScore(new Score("q1",90.1)); stu1.AddScore(new Score("q2",87.21)); stu1.AddScore(new Score("q3",94));
Student stu2 = newStudent("Daisy", 321); stu2.AddScore(new Score("q1",80.36)); stu2.AddScore(new Score("q2",92.70)); stu2.AddScore(new Score("q3",86.3));
Student stu3 = newStudent("Minny",876); stu3.AddScore(new Score("q1",75.75)); stu3.AddScore(new Score("q2",83.45)); stu3.AddScore(new Score("q3",78.98));
Student stu4 = newStudent("Mikey",543); stu4.AddScore(new Score("q1",60.99)); stu4.AddScore(new Score("q2",78.67)); stu4.AddScore(new Score("q3",50.38));
//PassFailCourse objectstored in Course object reference variable Course cou = newPassFailCourse("Underwater Basket Weaving"); System.out.println("AddStudent to course successfully ->"+cou.addStudent(stu1)); System.out.println("AddStudent to course successfully ->"+cou.addStudent(stu2)); System.out.println("AddStudent to course successfully ->"+cou.addStudent(stu3)); System.out.println("AddStudent to course successfully ->"+ cou.addStudent(stu4)); //PassFailCourse overridescomputeCourseAverage so it returns the percentage of students thatare passing (at or above 75%) System.out.println("Percentage of students with grade above75% ->"+ cou.computeCourseAverage()); System.out.println("Number ofStudents in the Course ->"+ cou.getAllStudents().size()); System.out.println("toStringprints the following\n"+cou.toString());
}
}
Here are my errors
Tasks - PassFailCourse Class • Task 1: The PassFailCourse class contains all the functionality of the Course class as it is a child class of Course class. You are given the Course class in the provided.jar file named A3.jar. Task 2: A PassFailCourse object can be created by giving as an argument a course name as a String. Complete the method public Pass FailCourse(String courseName) to complete this task. See the method comments for more detail. • Task 3: The user can get the percentage of students in the course on track to pass this PassFailCourse. The method will return a String containing the percent of students who's average of all the student's quizzes is at or better then 75% currently. Complete the method public double compute Course Average() to complete this task. The public double compute Course Average() overrides the method of of the superclass. See the method comments for more detail. • Task 4: The user will be able to ask for the textual representation of this PassFailCourse instance. The String includes the course name, type of course, percentage of the class that are above 75% average, and the superclass' toString. The method will return a String in the form specified in the example below. Complete the method public String toString() to complete this task. See the method comments for more detail. • Underwater Basket Weaving is a pass/fail course. 75.00% of the class are on track to pass the course. Students in this course: [Bugsy 521, Daisy 321, Minny 876, Mikey 543] Test your code using the A4PassFailDriver class, then submit your code on Gradescope. Fix any issues and resubmit to Gradescope as many time before the deadline as needed to maximize your score for this task. A4Pass FailDriver Example Output Add Student to course successfully ->true Add Student to course successfully ->true Add Student to course successfully ->true Add Student to course successfully ->true Percentage of students with grade above 75% ->75.0 Number of Students in the Course ->4 toString prints the following Underwater Basket Weaving is a pass/fail course. 75.00% of the class are on track to pass the course. Students in this course: [Bugsy 521, Daisy 321, Minny 876, Mikey 543]
package assignment; public class A4Pass FailDriver { public static void main(String[] args) { //NOTE: BELOW IS A STARTER SET OF TEST FOR YOUR ASSIGNMENT. //IT IS NOT THE ONLY SET OF TESTS YOU SHOULD DO FOR YOUR ASSIGNMENT ! //Student Class Student stul = new Student ("Bugsy", 521); stul. AddScore (new Score ("q1", 90.1)); stul.AddScore (new Score ("q2", 87.21)); stul. AddScore (new Score ("q3", 94)); Student stu2 = new Student ("Daisy", 321); stu2.AddScore (new Score ("q1", 80.36)); stu2. AddScore (new Score ("q2", 92.70)); stu2. AddScore (new Score ("q3", 86.3)); Student stu3 = new Student ("Minny", 876); stu3.AddScore (new Score ("q1", 75.75)); stu3.AddScore (new Score ("q2", 83.45)); stu3.AddScore (new Score ("q3", 78.98)); Student stu4 = new Student ("Mikey", 543); stu4.AddScore (new Score ("ql", 60.99)); stu4.AddScore (new Score ("q2", 78.67)); stu4.AddScore (new Score ("q3", 50.38)); //PassFailCourse object stored in Course object reference variable Course cou = new Pass FailCourse ("Underwater Basket Weaving"); System.out.println("Add Student to course successfully ->"+ cou.addStudent (stul)); System.out.println("Add Student to course successfully ->"+ cou.addStudent (stu2)); System.out.println("Add Student to course successfully ->"+ cou.addStudent (stu3)); System.out.println("Add Student to course successfully ->"+ cou.addStudent (stu4)); //PassFailCourse overrides computeCourseAverage so it returns the percentage of students that are passing (at or above 75%) System.out.println("Percentage of students with grade above 75% ->"+ cou.compute CourseAverage () ); System.out.println("Number of Students in the Course ->"+ cou.getAllStudents ().size()); System.out.println("toString prints the following\n"+cou.toString());