I need to be able to search my directory. I have listed code that I currently ha
ID: 3711929 • Letter: I
Question
I need to be able to search my directory. I have listed code that I currently have. I have had a lot of trouble getting the program to be listed alphabetically and allow me to search for a specific entry. I can get it to do one or the other, but not both. Please help me make this happen using the code listed below. I am sure that it is something simple that I am missing.
\ Directory Class
import java.util.*;
import java.text.*;
import java.lang.*;
public class Directory
{
private static Map<String, Person>students = new TreeMap<>();
private static Map<String, Person>person = new TreeMap<>();
public Directory()
{
}
public void printAllPersons()
{
for(String key : person.keySet())
{
System.out.println(key + " " + person.get(key));
}
}
public void printAllStudents()
{
for(String key : students.keySet())
{
System.out.println(key + " " + students.get(key));
}
}
public void addStudent(Person s)
{
person.put(s.getLastName() + " " + s.getFirstName(), s);
students.put(s.getLastName() + " " + s.getFirstName(), s);
}
public void addFaculty(Person f)
{
person.put(f.getLastName() + " " + f.getFirstName(), f);
}
public void addStaff(Person st)
{
person.put(st.getLastName() + " " +st.getFirstName(),st);
}
public void removePerson(Person removePerson)
{
person.remove(removePerson.getLastName() + " " +
removePerson.getFirstName(), removePerson);
students.remove(removePerson.getLastName() + " " +
removePerson.getFirstName(), removePerson);
}
}
\Person Class
import java.util.*;
public abstract class Person extends Directory
{
public String firstName;
public String lastName;
public String emailAddress;
public String name;
public Person()
{
}
public String getLastName()
{
return lastName;
}
public String getFirstName()
{
return firstName;
}
public void printPerson()
{
System.out.println(name + " " + emailAddress);
System.out.println();
}
@Override
public String toString()
{
return this.getClass().getName() + " " + name;
}
}
\Student Class
import java.util.*;
public class Student extends Person
{
private String Class;
private String studentID;
public Student(String firstName, String lastName, String emailAddress, String Class, String studentID)
{
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.Class = Class;
this.studentID = studentID;
name = lastName + ", " + firstName;
}
public void printStudent()
{
System.out.println(name + " " + emailAddress);
System.out.println();
}
public void updateStudent(String firstName, String lastName,
String emailAddress, String Class, String studentID)
{
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.Class = Class;
this.studentID = studentID;
name = lastName + ", " + firstName;
}
@Override
public String toString()
{
return "Student[" + super.toString() + "Class=" + Class +
", studentId=" + studentID +"]";
}
}
\Staff Class
import java.util.*;
public class Staff extends Person
{
private String jobTitle;
private String department;
private String title;
public Staff(String firstName, String lastName, String emailAddress, String jobTitle, String department, String title)
{
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.jobTitle = jobTitle;
this.department = department;
this.title = title;
name = lastName + ", " + firstName;
}
public void updateStudent(String firstName, String lastName,
String emailAddress, String department, String title)
{
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.department = department;
this.title = title;
name = lastName + ", " + firstName;
}
@Override
public String toString()
{
return "Staff [" + super.toString() + "jobTitle=" + jobTitle +
", department=" + department + ", title=" + title + "]";
}
}
\Faculty Class
import java.util.*;
public class Faculty extends Person
{
private int officeNumber;
private boolean tenure;
public Faculty(String firstName, String lastName, String emailAddress, int officeNumber, boolean tenure)
{
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.officeNumber = officeNumber;
this.tenure = tenure;
name = lastName + ", " + firstName;
}
public void updateFaculty(String firstName, String lastName,
String emailAddress, int officeNumber, boolean tenure)
{
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
this.officeNumber = officeNumber;
this.tenure = tenure;
name = lastName + ", " + firstName;
}
@Override
public String toString()
{
return "Faculty [" + super.toString() + " officeNumber=" +
officeNumber + ", tenure=" + tenure + "]";
}
}
Explanation / Answer
//////////// here equal method used to compare the directory class. write here specific condition to compare two objects of the directory are equal or not.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.