@@ -30,20 +30,55 @@ public String studentInfo() {
3030
3131
3232 //TODO: Uncomment and complete the getGradeLevel method here:
33- // public String getGradeLevel() {
34- // // Determine the grade level of the student based on numberOfCredits
35- // }
33+ public static String getGradeLevel (int credits ) {
34+ if (credits <= 29 ){
35+ return "freshman" ;
36+ } else if (credits <= 59 ){
37+ return "sophomore" ;
38+ } else if (credits <= 89 ) {
39+ return "junior" ;
40+ } else {
41+ return "senior" ;
42+ }
43+ }
3644
3745 // TODO: Complete the addGrade method.
3846 public void addGrade (int courseCredits , double grade ) {
39- // Update the appropriate fields: numberOfCredits, gpa
47+ // Calculate quality score for the new course
48+ double qualityScore = grade * courseCredits ;
49+
50+ // Update total quality score and number of credits
51+ double totalQualityScore = this .gpa * this .numberOfCredits ;
52+ totalQualityScore += qualityScore ;
53+ this .numberOfCredits += courseCredits ;
54+
55+ // Calculate new GPA
56+ this .gpa = totalQualityScore / this .numberOfCredits ;
4057 }
4158
4259 // TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather
4360 // than just the class fields.
61+ public String toString () {
62+ return "Student = " + name + " / ID = " + studentId +
63+ " / Credits = " + numberOfCredits + " / GPA = " + gpa ;
64+ }
4465
4566 // TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
4667 // Student objects equal.
68+ public boolean equals (Object toBeCompared ) {
69+ if (toBeCompared == this ) {
70+ return true ;
71+ }
72+ if (toBeCompared == null ) {
73+ return false ;
74+ }
75+ if (toBeCompared .getClass () != getClass ()) {
76+ return false ;
77+ }
78+ Student theStudent = (Student ) toBeCompared ;
79+ return theStudent .getStudentId () == getStudentId ();
80+ }
81+
4782
4883 public String getName () {
4984 return name ;
0 commit comments