Chapter 9 presented an Instructor class that holds information about an instructor. (See Section 9-7--Aggregation) Modify the Instructor class by overriding the hashCode and equals method. Then write a class that stores several Instructor objects in a HashSet. The class should be able to display all of the instructor in the set and allow the user to search for an instructor. Demonstrate the class in an application.
So the code from that project was:
/**
This class stores data about an instructor.
*/
public class Instructor
{
private String lastName; //last name
private String firstName; //first name
private String officeNumber; //office number
/**
Constructor initializes the last name,
first name, and office number.
@param lname the instructor's last name
@param fname the instructor's first name
@param office the office number
*/
public Instructor(String lname, String fname, String office)
{
lastName = lname;
firstName = fname;
officeNumber = office;
}
/**
Constructor initializes object as a copy of another instructor object.
@param object2 the object to copy
*/
public Instructor(Instructor object2)
{
lastName = object2.lastName;
firstName = object2.firstName;
officeNumber = object2.office;
}
/**
The set method sets a value for each field
@param lname the instructor's last name
@param fname the instructor's first name
*/
public void set(String lname, String fname, String office)
{
lastName = lname;
firstName = fname;
officeNumber = office;
}
/**
toString method
@return a string containing the instructor's information
*/
public String toString()
{
//create a string representing the object
String str = "Last Name: "+ lastName +
"\nFirst Name: " + firstName +
"\nOffice Number: "+ officeNumber;
//return the string
return str;
}
}
}
I'm having trouble understanding what the assignments specs mean when it says "modify the instructor class by overriding the hashCode and equals method". What is that referring to? Neither of those methods are in the code above... Please help, thanks

New Topic/Question
Reply



MultiQuote







|