Tasks - PassFailCourse Class Task 1: The PassFailCourse class contains all the functionality of the Course class as it i

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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 i

Post by answerhappygod »

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 PassFailCourse(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 computeCourseAverage() to complete this task. The public double computeCourseAverage() 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.
A4PassFailDriver Example Output
Add Student to course successfully ->trueAdd Student to course successfully ->trueAdd Student to course successfully ->trueAdd Student to course successfully ->truePercentage of students with grade above 75% ->75.0Number of Students in the Course ->4toString prints the followingUnderwater 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]
PASS FAIL TEMPLATE:
package assignment;
public class PassFailCourse extends Course { //See Assignment 3 or "High Level View of Your Tasks" in Folio to see what Course contains /** * This overrides Course's computerCourseAverage method. * The course is Pass / Fail, which means you will not receive a specific grade. * however, you need a 75% average to pass the course. * (Remember that the Student class has computeMyAverage as a method) * @return the number of students who's average of all the student's quizzes is 75% or better divided by the total students in the course */ @Override public double computeCourseAverage() { return -1.0; } /** * Name of this Pass/Fail Course * @param courseName */ public PassFailCourse(String courseName) { super("CHANGE THIS"); } /** * @return a string that mentions the course name, type of course, percentage of the class that have above 75% average, and the super's toString * e.g.
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]
*/ public String toString() { return ""; }}
PASS FAIL DRIVER:
package assignment;public class A4PassFailDriver {
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 stu1 = new Student("Bugsy",521); stu1.AddScore(new Score("q1", 90.1)); stu1.AddScore(new Score("q2", 87.21)); stu1.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("q1", 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 PassFailCourse("Underwater Basket Weaving"); System.out.println("Add Student to course successfully ->"+ cou.addStudent(stu1)); 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.computeCourseAverage()); System.out.println("Number of Students in the Course ->"+ cou.getAllStudents().size()); System.out.println("toString prints the following\n"+cou.toString());
}
}
COURSE CLASS:
package assignment;
import java.util.ArrayList;
public class Course {
ArrayList<Student> allStudents;
//default constructor
public Course() {
allStudents = new ArrayList<Student>();
}
/**
* @return the allStudents
*/
public ArrayList<Student> getAllStudents() {
return allStudents;
}
/**
* @param allStudents the allStudents to set
*/
public void setAllStudents(ArrayList<Student> allStudents) {
this.allStudents = allStudents;
}
// addStudent method
public boolean addStudent(Student stu) {
if(stu==null){
return false;
}
for(Student student: allStudents){
if(student.equals(stu)){
return false;
}
}
return allStudents.add(stu);
}
// Remove student method
public boolean removeStudent(Student stu) {
if(stu==null){
return false;
}
for(Student student : allStudents){
if(student.equals(stu)){
return allStudents.remove(stu);
}
}
return false;
}
// Update student method
public boolean updateStudent(Student stu) {
if(stu==null){
return false;
}
if(allStudents.contains(stu)){
allStudents.set(allStudents.indexOf(stu), stu);
return true;
}
return false;
}
/**
*
* @return the average of all the student's quizzes
*/
public double computeCourseAverage() {
double scoresAvgSum = 0.0;
int totalScores = 0;
for(int i = 0;i<allStudents.size();i++){
if(allStudents.get(i) != null) {
Score[] studentScores = allStudents.get(i).getAllMyScores();
for(int j = 0; j < studentScores.length; j++) {
if(studentScores[j] != null) {
scoresAvgSum += studentScores[j].getScoreValue();
totalScores++;
}
}
}
}
return scoresAvgSum/totalScores;
}
}
package assignment;
public class Student { /** * Use an array to store Score objects for the quizzes * A student has at most 10 Quiz scores */ // member variables private static int numberOfStudentobjects = 0; Score scoreObjects[] = new Score[10]; String stuName; int stuId; Score score; int scoreCounter = 0; private Score[] arrayOfScores; /** * Constructor * A student has at most 10 Quiz scores * @param id The student's ID. * @param stuName The student's name. */ public Student(String stuName, int stuID) { this.stuId = stuID; this.stuName = stuName; numberOfStudentobjects++; } /** * @return the array with all My Quiz Scores */ public Score[] getAllMyScores() { return scoreObjects; } public int getStuId() { return stuId; } public void setStuId(int stuId) { this.stuId = stuId; } public Score getScore() { return score; } public void setScore(Score score) { this.score = score; }
/** * @param an array with Quiz Scores used to set my current quiz scores */ public void setAllMyScores(Score[] arrayOfScores) { this.scoreObjects = arrayOfScores; } /** * toString method * Example return: * "Bugsy 123456" * @return A string with the student's ID number * and name. */ public String toString() { return stuName + " " + stuId; } /** * equals method * @param another Student object (remember to cast) * @return A boolean - true if this student's ID number * and name matches this student's ID number and name. */ @Override public boolean equals(Object that) { Student tempCast = (Student)that; if(this.stuName.equals(tempCast.getStuName()) && this.stuId == getStuId()) { return true; }else { return false; } } /** * updateScore method * @param scoreName - name of the Score object to search for and update * @param newScoreVal - new value for the searched quiz. * @return A boolean - true if the quizName already exist for this student * and the score is valid and the score array was successfully updated. */ public boolean updateAScore(String scoreName, double newScoreVal) { // check scoreName is valid if (scoreName == null) { return false; } for(int i = 0; i <scoreObjects.length; i++) { if(scoreObjects != null) { if(scoreObjects.getScoreName().equals(scoreName)) { scoreObjects.setScoreValue(newScoreVal); return true; } } } return false; } /** * AddScore method * @param newScore - the Score object to Add. * @return A boolean - true if the quizName didn't exist for this student * and the score is valid and the score array was successfully updated. */ public boolean AddScore(Score newScore) { // if not valid score if (newScore == null) { return false; } for (int i = 0; i < scoreObjects.length; i++) { if(scoreObjects != null) { if (scoreObjects.getScoreName() == newScore.getScoreName()) { return false; } } } for(int i = 0; i < scoreObjects.length; i++) { if (scoreObjects == null) { scoreObjects = newScore; } } return true; } /** * @param scoreName - name of quiz to get score * @return the score for the quiz or -1 if quizName is invalid */ public double getAScore(String scoreName) { if(scoreName == null) { return -1; } for(int i = 0; i < scoreObjects.length; i++) { if(scoreObjects != null) { if(scoreObjects.getScoreName().equals(scoreName)) { return scoreObjects.getScoreValue(); } } } return -1; } /** * computeMyAverage method * Computes the average of the valid scores in this student's array * e.g. - student array -> {50, null, 100, null, 150}, the average would be 100 * @return this student's average score */ public double computeMyAverage() { double sum = 0; int count = 0; // loop over all scores for (int i = 0; i < scoreObjects.length; i++) { // if not a valid score, continue loop if (scoreObjects[i] == null) continue; if (scoreObjects[i].getScoreValue() == -1) continue; // add to sum sum += scoreObjects[i].getScoreValue(); // increment count count++; } // if valid score exists if (count > 0) return sum / count; return -1.0; } /** * getNumberOfStudentsCreated method * Keeps track of the number of Student instances * @return the total number of Student objects instantiated */ public static int getNumberOfStudentsCreated() { return numberOfStudentobjects; } /** * @return the stuName */ public String getStuName() { return stuName; } /** * @param stuName the stuName to set */ public void setStuName(String stuName) { this.stuName = stuName; } /** * @return the id */ public int getId() { return stuId; }}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply