Aldin-SXR

compareTo()

Mar 19th, 2020
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. /* Compare "this" student to "that" student (the other object) */
  2. public int compareTo(Student that) {                                // 1
  3.     if (this.gpa > that.gpa) {                                      // 2
  4.         return 1;                                                   // 2
  5.     } else if (this.gpa < that.gpa) {                               // 3
  6.         return -1;                                                  // 3
  7.     } else {                                                        // 4
  8.         return 0;                                                   // 4
  9.     }
  10. }
Advertisement
Add Comment
Please, Sign In to add comment