Advertisement
Guest User

Student Class Text

a guest
Mar 30th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. package databasev1_2020;
  2.  
  3. /**
  4.  * Student class for use in our database project Students need to have a first
  5.  * and last name, unique id and a debt amount
  6.  *
  7.  */
  8. public class Student implements Comparable {
  9.  
  10.     // Declare the private data that each student "has"
  11.     private String myFirst;
  12.     private String myLast;
  13.     private int myID;
  14.     private double myDebt;
  15.  
  16.     // Constructor to create each new student
  17.     // Remember, constructor headers (names) must be IDENTICAL to class header
  18.  
  19.     public Student(String first, String last, int id) {
  20.         myFirst = first;
  21.         myLast = last;
  22.         myID = id;
  23.         myDebt = 0.0;
  24.     }
  25.  
  26.     // Accessor methods retrieve individual student data
  27.     public String getFirst() {
  28.         return myFirst;
  29.     }
  30.  
  31.     public String getLast() {
  32.         return myLast;
  33.     }
  34.  
  35.     public int getID() {
  36.         return myID;
  37.     }
  38.  
  39.     public double getDebt() {
  40.         return myDebt;
  41.     }
  42.  
  43.     public void changeDebt(double newdebt) {
  44.         myDebt = newdebt;
  45.     }
  46.  
  47.     @Override
  48.     public int compareTo(Object obj) {
  49.         Student stud = (Student) obj;
  50.         if (myLast.compareTo(stud.myLast) == 0) {
  51.             return myFirst.compareTo(stud.myFirst);
  52.         } else {
  53.             return myLast.compareTo(stud.myLast);
  54.  
  55.         }
  56.     }
  57.  
  58.     @Override
  59.     public boolean equals(Object obj) {
  60.         return myID == ((Student) obj).myID;
  61.  
  62.     }
  63.  
  64.     @Override
  65.     public String toString() {
  66.         return myFirst + " " + myLast + " (id : " + myID + ")";
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement