i hope you can solve this problem during 1 hour.:P
Answer all of the following questions.
a. Create a Student class that has:
i. Two instance variables, name and id.
ii. Two constructors with the following headers :
public Student(int id, String name)
public Student(int id)
iii. Two get (accessor) methods for the two instance variables.
iv. An appropriate toString method
v. A compareTo method with the following header:
protected int compareTo(Comparable object)
that does the comparison based on student id’s.
b. Write a class, MatchingVisitor, whose constructor takes an instance of Comparable (target) as argument and finds whether the target exists in the container. Your visitor should have two additional methods as described below:
public boolean isFound() : returns true if a match is found, false otherwise.
public Comparable getMatch() : returns the reference to the matched object if found, null otherwise.
Note: Your visitor must stop the search as soon as it finds a match.
c. Write a menu-driven application that makes use of the Container and PrintingVisitor classes of lab01, the Student and the MatchingVisitor classes described above to maintain a record of students.
You application should have at least the following options:
Add a student Reads a student information from the user and adds it to the container.
Find a student Reads a student id from the user and finds if it exists in the container using the MatchingVisitor. If found, the full detail of the student should be displayed, otherwise an appropriate message is displayed.
List all students Prints all students in the container using a printing visitor
Exit Exit the application.