Page 1 of 1

Tasks - Student Class USE THIS TEMPLATE FOR THE STUDENT CLASS: package assignment; public class Student { /** * Use an a

Posted: Tue Jul 05, 2022 10:27 am
by answerhappygod
Tasks - Student Class
USE THIS TEMPLATE FOR THE STUDENT CLASS:
package assignment;
public class Student {
/*** Use an array to store Score objects for the quizzes* A student has at most 10 Quiz scores*//*** 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) {}/*** @return the array with all My Quiz Scores*/public Score[] getAllMyScores() {return null;}
/*** @param an array with Quiz Scores used to set my current quizscores*/public void setAllMyScores(Score[] arrayOfScores) {}
/*** toString method* Example return:* "Bugsy 123456"* @return A string with the student's ID number* and name.*/public String toString() {return "";}
/*** 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.*/public boolean equals(Object that) {return false;}/*** updateScore method* @param scoreName - name of the Score object to search for andupdate* @param newScoreVal - new value for the searched quiz.* @return A boolean - true if the quizName already exist for thisstudent* and the score is valid and the score array was successfullyupdated.*/public boolean updateAScore(String scoreName, double newScoreVal){return false;}/*** AddScore method* @param newScore - the Score object to Add.* @return A boolean - true if the quizName didn't exist for thisstudent* and the score is valid and the score array was successfullyupdated.*/public boolean AddScore(Score newScore) {return false;}/*** @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) {return -1.0;}/*** computeMyAverage method* Computes the average of the valid scores in this student'sarray* e.g. - student array -> {50, null, 100, null, 150}, theaverage would be 100* @return this student's average score*/public double computeMyAverage() {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 -1;}
/*** @return the stuName*/public String getStuName() {return "";}
/*** @param stuName the stuName to set*/public void setStuName(String stuName) {}
/*** @return the id*/public int getId() {return -1;}}
USE THIS DRIVER TO TEST THE STUDENT CLASS:
package assignment;
public class StudentDriver {
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 YOURASSIGNMENT!//Score classScore s1 = new Score("Quiz1", 80.09);Score s2 = new Score("qu12", 70.3333);//Student ClassStudent stu1 = new Student("Bugsy",123456);System.out.println("Call toString method of Student->"+stu1);System.out.println("Add a score to student->"+stu1.AddScore(s2));System.out.println("Get a score from student->"+stu1.getAScore("qu12"));System.out.println("Update a score from student->"+stu1.updateAScore("qu12", 99.91));stu1.AddScore(s1);System.out.println("Compute average for student->"+stu1.computeMyAverage());Student stu2 = new Student("Daisy", 321);System.out.println("Display number of Student Objects created->"+Student.getNumberOfStudentsCreated());System.out.println("Check if Student stu1 and stu2 are the same->"+stu1.equals(stu2));Student stu3 = new Student("Daisy",321);System.out.println("Check if Student stu2 and stu3 are the same->"+stu2.equals(stu3));Score[] testSetOfScores2 = {null,new Score("q1", 10),null,newScore("q2", 20),null, new Score("q3", 30),null, new Score("q4",40),null,new Score("q5", 50)};stu2.setAllMyScores(testSetOfScores2);System.out.println("Compute average for student->"+stu2.computeMyAverage());}
}
THE OUTPUT SHOULD BE:
Call toString method of Student ->Bugsy 123456Add a score to student ->trueGet a score from student ->70.3333Update a score from student ->trueCompute average for student ->90.0Display number of Student Objects created ->2Check if Student stu1 and stu2 are the same ->falseCheck if Student stu2 and stu3 are the same ->trueCompute average for student ->30.0