Advertisement
Aldin-SXR

Student.class

Mar 19th, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. package ds.bubble.sort.objects;
  2.  
  3. public class Student implements Comparable<Student> {
  4.    
  5.     String fullName;
  6.     String department;
  7.     double gpa;
  8.    
  9.     /* Constructor: set initial values of the Student object */
  10.     public Student(String fullName, String department, double gpa) {
  11.         this.fullName = fullName;
  12.         this.department = department;
  13.         this.gpa = gpa;
  14.     }
  15.  
  16.     /* Compare "this" student to "that" student (the other object) */
  17.     public int compareTo(Student that) {                                // 1
  18.         if (this.gpa > that.gpa) {                                      // 2
  19.             return 1;                                                   // 2
  20.         } else if (this.gpa < that.gpa) {                               // 3
  21.             return -1;                                                  // 3
  22.         } else {                                                        // 4
  23.             return 0;                                                   // 4
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement