Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Student class: fields- name, ID, array of 5 test scores and a double average. In

ID: 3536626 • Letter: S

Question

Student class: fields- name, ID, array of 5 test scores and a double average. Include a toString() method that returns the name, and average and an equals() method that determines if two Student objects are equal based on the value of their ID fields and a compareTo() method that uses the average field for ordering. Driver class- creat an array of 10 students. Read the data in from a text file which is field delimited by commas. The file will contain the name (first name space, then last name), id, and five scores for ten students. The average is a calculated field. Print each student's info on the screen using the toString() method for the student. Test and print your test results for both the equals() method and the compareTo() method. example text input file: Jon Wills, 1234, 89,97,78,75,90 Misty Spring, 2345,88,77,89,95,93

Explanation / Answer

Contents of the text file



Jon Wills, 1234, 89,97,78,75,90 Neil Armstrong, 1234, 80,57,48,35,70 Misty Spring, 2345,88,77,89,95,93 Richard Anderson, 3456, 78, 67, 56, 86, 90 John Williams, 4567, 89,97,78,78,92 James Will, 5678, 80,97,78,75,90 San Armstrong, 1234, 89,67,48,35,90 John Williams, 4567, 89,97,78,78,92 Jon Wills, 1234, 89,97,78,75,90









There are two classes. Student and driver. I am posting student.java here and driver.java I ll post on fresh question you post. Kindly rate here first. Have given comments throught the code for your better understanding. It would be great if you give in total 6000 points for satisfying your needs 100 %. Every single little thing has been taken care of.



Student.java






/*

Student class: fields- name, ID, array of 5 test scores and a double average.

Include a toString() method that returns the name, and average and an equals()

method that determines if two Student objects are equal based on the value of

their ID fields and a compareTo() method that uses the average field for ordering.


*/

public class Student implements Comparable<Student>{


private String name; //declaring a variable name of string type

private int ID; //declaring a variable ID of int type





double[] testScores = new double [5]; // an array testScores which is of double type

double average = 0; // a variable average initialized to 0

public String getName() // getter method of name

{

return name;

}


public String setName(String name) //setter method of name

{

return this.name = name;

}


public int getID() //getter method of ID

{

return ID;

}


public void setID(int iD) //setter method of ID

{

ID = iD;

}


@Override

public String toString() //to string method which has name and

//average as defined in problem definition.

{

return "[name=" + name + ", average=" + average + "]";

}


@Override

public int hashCode()// hash code method

{

final int prime = 31;

int result = 1;

result = prime * result + ID;

return result;

}


@Override

public boolean equals(Object obj)

//equals method

{

if (obj == null) // if you are comparing an object with another object was has nothing inside,

// i.e the object is null, then equals method ll return null.

return false;

Student other = (Student) obj;

if (ID == other.ID)// when two objects are compared. And the IDs of two objects are same.

//Doesnt matter if the names and testScores are different. It should return true.

return true;

return false;

}



public int compareTo(Student student) //CompareTo method

{

double compareAverage = ((Student) student).average;

return (int) (this.average - compareAverage);

  

}

/* A bit of intro for you. Why did I use hashcode and equals. The motive of hashcode method is to compare two

objects if they are equal. here In the question, you have mentioned that not the complete object should be

equal but if the ID of two objects are equal, then consider those objects to be equal.

In other words, you are not worried about other things. If two IDs of two different objects are equal

then equals method will return true.

CompareTo method is used for sorting. Here, You want to use compareTo method for the average field.

So The list will be sorted on the basis of average. I have sorted it in ascending order.

The lowest average will come first. Followed by second lowest and finally the highest average comes

at last. Hope that makes some sense for you.*/

}