Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package databasev1_2020;
- /**
- * Student class for use in our database project Students need to have a first
- * and last name, unique id and a debt amount
- *
- */
- public class Student implements Comparable {
- // Declare the private data that each student "has"
- private String myFirst;
- private String myLast;
- private int myID;
- private double myDebt;
- // Constructor to create each new student
- // Remember, constructor headers (names) must be IDENTICAL to class header
- public Student(String first, String last, int id) {
- myFirst = first;
- myLast = last;
- myID = id;
- myDebt = 0.0;
- }
- // Accessor methods retrieve individual student data
- public String getFirst() {
- return myFirst;
- }
- public String getLast() {
- return myLast;
- }
- public int getID() {
- return myID;
- }
- public double getDebt() {
- return myDebt;
- }
- public void changeDebt(double newdebt) {
- myDebt = newdebt;
- }
- @Override
- public int compareTo(Object obj) {
- Student stud = (Student) obj;
- if (myLast.compareTo(stud.myLast) == 0) {
- return myFirst.compareTo(stud.myFirst);
- } else {
- return myLast.compareTo(stud.myLast);
- }
- }
- @Override
- public boolean equals(Object obj) {
- return myID == ((Student) obj).myID;
- }
- @Override
- public String toString() {
- return myFirst + " " + myLast + " (id : " + myID + ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement