Tasks - Course Class Task 1: The user can add a Student object to the Course instance by giving the Student object as an
Posted: Tue Jul 05, 2022 10:26 am
Tasks - Course Class
Task 1: The user can add a Student object to the Courseinstance by giving the Student object as an argument to the method.The method will return a boolean, true if the argument is notalready in the Course's ArrayList and the ArrayList was updated inthe Course instance. The method will return false if the argumentis null or the Student object already exist in the Course'sArrayList and the ArrayList will not be updated in the Courseinstance. Complete the method public boolean addStudent(Studentstu) to complete this task. See the method comments for moredetail.
Task 2: The user can remove a Student object from theCourse instance by giving the Student object as an argument to themethod. The method will return a boolean, true if the argument isan existing Student object in the Course's ArrayList and theStudent object was removed from the ArrayList in the Courseinstance. The method will return false if the argument is null orthe Student object does not exist in the Course's ArrayList and theArrayList will not be updated in the Course instance. Complete themethod public boolean removeStudent(Student stu) to complete thistask. See the method comments for more detail.
Task 3: [EXTRA CREDIT] The user can update a Studentobject in the Course instance by giving the updated Student objectas an argument to the method. The method will return a boolean,true if the argument matches an existing Student object in theCourse's ArrayList and the existing Student object was replaced bythe argument in the ArrayList in the Course instance. The methodwill return false if the argument is null or the Student objectdoes not exist in the Course's ArrayList and the ArrayList will notbe updated in the Course instance. Complete the method publicboolean updateStudent(Student stu) to complete this task. See themethod comments for more detail.
Task 4: The user will be able to ask for the average ofall the Student objects in the Course instance. The methodwill ask each Student object for its' average of Scores anduse that to compute the average of the course which will return theaverage as a double. Complete the method public doublecomputeCourseAverage() to complete this task. See the methodcomments for more detail.
Task 5: Complete the get and set methods publicArrayList<Student> getAllStudents(), public voidsetAllStudents(ArrayList<Student> allStudents) to completethis task. See the method comments for more detail.
USE THIS TEMPLATE FOR THE COURSE CLASS:
package assignment;
import java.util.ArrayList;
public class Course {
/**
* @return the allStudents
*/
public ArrayList<Student> getAllStudents(){
return null;
}
/**
* @param allStudents the allStudents to set
*/
public void setAllStudents(ArrayList<Student>allStudents) {
}
public boolean addStudent(Student stu) {
return false;
}
public boolean removeStudent(Student stu) {
return false;
}
public boolean updateStudent(Student stu) {
return false;
}
/**
*
* @return the average of all the student'squizzes
*/
public double computeCourseAverage() {
return -1.0;
}
}
USE THE DRIVER TO TEST THE COURSE CLASS:
package assignment;
public class CourseDriver {
public static void main(String[] args) {
//NOTE: BELOW IS A STARTER SET OF TEST FOR YOURASSIGNMENT.
//IT IS NOT THE ONLY SET OF TESTS YOU SHOULD DO FOR YOURASSIGNMENT!
//Score class
//Student Class
Student stu1 = new Student("Bugsy",521);
stu1.AddScore(new Score("qu12", 10));
stu1.getAScore("qu12");
stu1.updateAScore("qu12", 99.9);
stu1.AddScore(new Score("q2", 90.1));
Student stu2 = new Student("Daisy", 321);
Student stu3 = new Student("Daisy",321);
//Course class
Course cou = new Course();
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 unsuccessfully->"+ cou.addStudent(stu3));
Score[] testSetOfScores2 = {null,new Score("q1",90),null,new Score("q2", 80),null, new Score("q3", 90),null, newScore("q4", 80),null,new Score("q5", 90)};
stu2.setAllMyScores(testSetOfScores2);
Score[] testSetOfScores1 = {null,new Score("q1",100),null,new Score("q2", 80),null, new Score("q3", 70),null, newScore("q4", 90),null,new Score("q5", 90)};
stu1.setAllMyScores(testSetOfScores1);
System.out.println("Course average for all students->"+ cou.computeCourseAverage());
System.out.println("Number of Students in the Course->"+ cou.getAllStudents().size());
System.out.println("Attempt to remove a student that isin the course -> "+cou.removeStudent(stu2));
System.out.println("Number of Students in the Course->"+ cou.getAllStudents().size());
System.out.println("Attempt to remove a student that isNOT in the course -> "+cou.removeStudent(newStudent("Mikey",987)));
}
}
THE OUTPUT SHOULD BE:
CourseDriver.java:
Add Student to course successfully->true
Add Student to course successfully->true
Add Student to course unsuccessfully->false
Course average for all students ->86.0
Number of Students in the Course ->2
Attempt to remove a student that is in the course ->true
Number of Students in the Course ->1
Attempt to remove a student that is NOT in the course-> false
Task 1: The user can add a Student object to the Courseinstance by giving the Student object as an argument to the method.The method will return a boolean, true if the argument is notalready in the Course's ArrayList and the ArrayList was updated inthe Course instance. The method will return false if the argumentis null or the Student object already exist in the Course'sArrayList and the ArrayList will not be updated in the Courseinstance. Complete the method public boolean addStudent(Studentstu) to complete this task. See the method comments for moredetail.
Task 2: The user can remove a Student object from theCourse instance by giving the Student object as an argument to themethod. The method will return a boolean, true if the argument isan existing Student object in the Course's ArrayList and theStudent object was removed from the ArrayList in the Courseinstance. The method will return false if the argument is null orthe Student object does not exist in the Course's ArrayList and theArrayList will not be updated in the Course instance. Complete themethod public boolean removeStudent(Student stu) to complete thistask. See the method comments for more detail.
Task 3: [EXTRA CREDIT] The user can update a Studentobject in the Course instance by giving the updated Student objectas an argument to the method. The method will return a boolean,true if the argument matches an existing Student object in theCourse's ArrayList and the existing Student object was replaced bythe argument in the ArrayList in the Course instance. The methodwill return false if the argument is null or the Student objectdoes not exist in the Course's ArrayList and the ArrayList will notbe updated in the Course instance. Complete the method publicboolean updateStudent(Student stu) to complete this task. See themethod comments for more detail.
Task 4: The user will be able to ask for the average ofall the Student objects in the Course instance. The methodwill ask each Student object for its' average of Scores anduse that to compute the average of the course which will return theaverage as a double. Complete the method public doublecomputeCourseAverage() to complete this task. See the methodcomments for more detail.
Task 5: Complete the get and set methods publicArrayList<Student> getAllStudents(), public voidsetAllStudents(ArrayList<Student> allStudents) to completethis task. See the method comments for more detail.
USE THIS TEMPLATE FOR THE COURSE CLASS:
package assignment;
import java.util.ArrayList;
public class Course {
/**
* @return the allStudents
*/
public ArrayList<Student> getAllStudents(){
return null;
}
/**
* @param allStudents the allStudents to set
*/
public void setAllStudents(ArrayList<Student>allStudents) {
}
public boolean addStudent(Student stu) {
return false;
}
public boolean removeStudent(Student stu) {
return false;
}
public boolean updateStudent(Student stu) {
return false;
}
/**
*
* @return the average of all the student'squizzes
*/
public double computeCourseAverage() {
return -1.0;
}
}
USE THE DRIVER TO TEST THE COURSE CLASS:
package assignment;
public class CourseDriver {
public static void main(String[] args) {
//NOTE: BELOW IS A STARTER SET OF TEST FOR YOURASSIGNMENT.
//IT IS NOT THE ONLY SET OF TESTS YOU SHOULD DO FOR YOURASSIGNMENT!
//Score class
//Student Class
Student stu1 = new Student("Bugsy",521);
stu1.AddScore(new Score("qu12", 10));
stu1.getAScore("qu12");
stu1.updateAScore("qu12", 99.9);
stu1.AddScore(new Score("q2", 90.1));
Student stu2 = new Student("Daisy", 321);
Student stu3 = new Student("Daisy",321);
//Course class
Course cou = new Course();
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 unsuccessfully->"+ cou.addStudent(stu3));
Score[] testSetOfScores2 = {null,new Score("q1",90),null,new Score("q2", 80),null, new Score("q3", 90),null, newScore("q4", 80),null,new Score("q5", 90)};
stu2.setAllMyScores(testSetOfScores2);
Score[] testSetOfScores1 = {null,new Score("q1",100),null,new Score("q2", 80),null, new Score("q3", 70),null, newScore("q4", 90),null,new Score("q5", 90)};
stu1.setAllMyScores(testSetOfScores1);
System.out.println("Course average for all students->"+ cou.computeCourseAverage());
System.out.println("Number of Students in the Course->"+ cou.getAllStudents().size());
System.out.println("Attempt to remove a student that isin the course -> "+cou.removeStudent(stu2));
System.out.println("Number of Students in the Course->"+ cou.getAllStudents().size());
System.out.println("Attempt to remove a student that isNOT in the course -> "+cou.removeStudent(newStudent("Mikey",987)));
}
}
THE OUTPUT SHOULD BE:
CourseDriver.java:
Add Student to course successfully->true
Add Student to course successfully->true
Add Student to course unsuccessfully->false
Course average for all students ->86.0
Number of Students in the Course ->2
Attempt to remove a student that is in the course ->true
Number of Students in the Course ->1
Attempt to remove a student that is NOT in the course-> false