Question: Please help me code the following in JAVA Please read the task thoroughly, and include many COMMENTS so I can understand! Full points will be
Please help me code the following in JAVA
Please read the task thoroughly, and include many COMMENTS so I can understand!
Full points will be awarded, thanks in advance!

InterfaceDriver class:
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import javax.swing.JFrame; public class InterfaceDriver { //comment and uncomment the demo functions in main to test public static void main(String[] args) { comparableDemo(); cloneableDemo(); serializableDemo(); actionListenerDemo(); } public static void actionListenerDemo() { Application a = new Application(); } public static void serializableDemo() { writeObjectsToFile(); readObjectsFromFile(); } private static void readObjectsFromFile() { try { //ObjectInputStream is = new ObjectInputStream( new FileInputStream("object.dat")); ObjectInputStream is = new ObjectInputStream(new FileInputStream("data.obj")); StudentClass a = (StudentClass)is.readObject(); //cast is required since object is returned StudentClass b = (StudentClass)is.readObject(); System.out.println("From file : " + a); System.out.println("From file : " + b); is.close(); } catch (Exception e) { e.printStackTrace(); System.err.println("Bad OOS"); } } private static void writeObjectsToFile() { try { //ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream("object.dat")); ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("data.obj")); StudentClass a = new StudentClass("FileIO1", 3.0); StudentClass b = new StudentClass("FileIO2", 4.0); os.writeObject(a); os.writeObject(b); os.close(); } catch (Exception e) { e.printStackTrace(); System.err.println("Bad OOS"); } } public static void comparableDemo() {
StudentClass a = new StudentClass("Rob", 3.0); StudentClass b = new StudentClass("Bill", 4.0); StudentClass c = new StudentClass("Mary", 4.0); System.out.println( " a compareTo b :" + a.compareTo(b)); System.out.println( " b compareTo a :" + b.compareTo(a)); System.out.println( " b compareTo c :" + b.compareTo(c)); } public static void cloneableDemo() { StudentClass a = new StudentClass("Evan", 3.0); StudentClass c = (StudentClass)a.clone(); System.out.println(a); System.out.println(c); System.out.println("Changing object a"); a.setName("Boo"); a.setGPA(3.5); System.out.println(" new name: " + a.getName()); System.out.println(" new GPA: " + a.getGPA()); System.out.println(" The object a: " + a); System.out.println(" The object c: " + c); } }
Implementing the Comparable Interface for Sorting We start by building a Student class that tracks their name and GPA, and then turn to implementing the Comparable Interface for this class. The idea is that we should be able to compare two students by their GPA and then sort a collection of students in order relative to their GPAs. (1) Build a Student Class with only two data items: a String name and a double GPA. (2) Modify the class definition so that it "implements Comparable" (3) When designing the compareTo() method, use the GPA to determine if student1>student2. Consider returning the difference between the two students as the magnitude of difference (either positive or negative) a. 4) Build main to test your Students, and in this main build a list of 10 Students with different GPAs. (5) Download and run the InterfaceDriver to test comparing students (comparableDemo in code) Implementing the Cloneable Interface There are two examples in this section for the Cloneable interface. We'll do the first one together, which is making students cloneable. (1) Add "implements Cloneable" to your Student class definition (2) Define the clone method using "@Override", make it public and return a new student object a. Build a copy constructor and then the clone is just one line of code "return new Student(this)," Run the corresponding driver code to test Student clones. i. (3)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
