import javax.swing.*; class Student implements Cloneable{ //class var private static int count= 0; //attributes/data members of the class //instance vars private String first; private String last; private int midterm; private int myFinal; private int id; //behaviors of the class //constructors -- purpose is to initialize data members of the class //more than one constructor allowed. Default constructor -- the one that requires //parameters. public Student() //default { first = "none"; last = "none"; midterm = 0; myFinal = 0; id = 0; count ++; } public Student (int id, String myFirst, String myLast, int myMidterm, int theFinal) { first = myFirst; last = myLast; midterm = myMidterm; myFinal = theFinal; this.id = id; count ++; } //override inherited method from Object public Object clone() throws CloneNotSupportedException {Student theCopy; theCopy = (Student) super.clone(); return (theCopy); } //set and get methods to provide read and write access to private data //set methos provide write access to private data. public boolean setMidterm(int newValue) {boolean success = true; if(newValue > 0 && newValue <= 100) midterm = newValue; else success = false; return success; } public boolean setFinal(int newValue) {boolean success = true; if (newValue > 0 && newValue <= 100) myFinal = newValue; else success = false; return success; } //get methods provide read access to private data public int getMidterm() {return midterm; } public int getId() {return id; } public String getFirst() {return first;} public String getLast() {return last; } public int compareTo(Student rhs) { if (last.compareTo(rhs.last) > 0) return 1; else if (last.compareTo(rhs.last) < 0) return -1; else {//last names are equal, now check for first if (first.compareTo(rhs.first) >0) return 1; else if (first.compareTo(rhs.first) <0) return -1; else return 0; }//else } public float computeAverage() { float theAvg = 0.0f; theAvg = midterm * .4f + myFinal * .6f; return theAvg; } public static int getCount() {return (count); } public String toString(){ return("Name: " + first + " " + last + "\tID: " + id + "\nMidterm: " + midterm + "\nFinal: " + myFinal +"\n"); } public boolean equals(Student rhs) { return (id == rhs.id); } protected void finalize() { --count; System.out.println("Finalizer executing now"); //if "extended" another class (other than Object) //you must call super.finalize() as the last line of your finalize //super.finalize(); } } // End of class