Question: Below are the requirements for my project and the code that I have already completed. The only thing that I cannot get the code to
Below are the requirements for my project and the code that I have already completed. The only thing that I cannot get the code to do it retrieve a person from the TreeMap.
Create a BlueJ project that maintains a student, faculty and staff directory. Your project should be able to add new entries, update entries and print the entries alphabetically by name. In addition, you should be able to remove an entry or print an entry given the entry name.
Assume the entries have the following fields:
All Persons
First name
Last name
Email address
Students
Class (e.g. freshman, sophmore, junior, senior)
Student ID (e.g. T09910754)
Staff
Job Title (e.g. Analyst)
Department (e.g. Information Technology)
Title (e.g. Mr., Ms.)
Faculty
Office Number (e.g. Room 308)
Tenured (Boolean)
The directory should contain these methods:
Add person
Print all people (alphabetically by name)
Print just Students
Remove a person
Retrieve a person
You should develop an hierarchical class structure that minimizes duplication among the classes. Each class should overload the toString() method to produce an appropriate String to be used as the directory listing. The listing should be produced by iterating through the Collection of entries, using the toString() method to print each entry. Since you want to display the directory alphabetically, you might consider using a Tree Map Collection to store your database, creating the key by concatenating the last and first name. To facilitate implementation of the remove and retrieve methods, add a getter method to the Person class to return the key of the object.
\\ Directory Class
import java.util.*; import java.text.*; import java.lang.*;
public class Directory { private static Map
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 + "]"; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
