Question: Question 1: Write a student class to represent students. Each student has a name, a unique ID, and a phone number. Students can choose

Question 1: Write a student class to represent students. Each student has a name, a unique ID, and a phonepersons Question 2: Now consider the more general case where we would like to model other types of beyond

Question 1: Write a student class to represent students. Each student has a name, a unique ID, and a phone number. Students can choose to add courses or drop courses. No student has access to the research lab, but a student has access to the library if he/she is taking at least one course. The Student class should have the following public interface: 1. public Student(String name, String phoneNumber): A constructor to set up student's name, phone number, and ID. Hint: Follow the BankAccount example discussed under the topic "Designing Classes" to generate the ID for each student object. 2. public String getStudentName(): An accessor to return the student's name. 3. public String getStudentPhone(): An accessor to return the student's phone number. 4. public int getStudentId(): An accessor to return the student's ID. 5. public boolean addCourse(String courseName): A method to add courses. The max course load of each student is five courses. Any attempt to add more than five courses will fail and this method will return false. Return true when the course is added successfully. 6. public boolean dropCourse(String courseName): A method to drop a course. This method will remove the course from the student's course load. If there is no such course in the student's course load or the student has not enrolled in any course, the method will return false. 7. public int getCourseCount(): A method to return the number of courses that student has enrolled. 8. public boolean hasAccessToLibrary(): A method that indicates whether the student has access to the library. If the number of courses enrolled is greater than zero, the student will have the access to library. 9. public boolean hasAccessToResearchLab(): A method that indicates whether the student has access to the research lab. Return false. Note that in the implementation above, use only the language elements that were covered in Weeks 1 -3 (September 7, 14, and 21). Write a tester program Task1Tester to thoroughly test the class you have written. Follow the examples given in class (See Slides 42-44 of "Implementing Classes" posted on eClass). This tester class is to help you make sure your Student class works as intended. persons Question 2: Now consider the more general case where we would like to model other types of beyond Student. For this, we design a hierarchy of classes to represent the different types of people. At the top of the class hierarchy, write an abstract class called Person with methods common to different types of people. Person has the following public interface: 1. public Person(String name, String phoneNumber, String type): A constructor to initialize the person's name and phone number. Hint: Follow the BankAccount example discussed under the topic "Designing Classes" to generate the ID for each person object. 2. public String getName(): An accessor to return the person's name. 3. public String getPhoneNumber(): An accessor to return the person's phone number. 4. public int getId(): An accessor to return the person's id. 5. public String getType(): An accessor to return a string that represents the type of person. 6. public abstract boolean hasAccessToLibrary(): A method that indicates whether the person has access to the library. This should be overridden by the subclass. 7. public abstract boolean hasAccessToResearchLab(): A method that indicates whether the person has access to the research lab. This should be overridden by the subclass. Once Person is defined, you must then provide a different implementation of the student concept above with a new class name Student2 and define a new class Instructor, both of which inherit from Person: Student2 should be implemented to keep the attributes and behaviors specified in Question 1. The class Instructor represents instructors. All instructors have access to the library. Assume that each instructor is assigned to teach one course and this assignment will not change. Each instructor may also have a research project, and only instructors having a research project can access the research lab.should have the following public interface: 1. public Instructor(String name, String phoneNumber, String courseId): A constructor to set up the instructor name, phone number and course. Each instructor should have a unique ID just like in Student and Person. 2. public boolean setReserachProject(String project): A method to set the research project for the instructor. If the instructor has already had a project, the old project will be replaced by the given project. 3. public String getProject(): return the research topic of the instructor. 4. public boolean hasAccessToLibrary(): A method that indicates whether the instructor has access to the library. Always return true. 5. public boolean hasAccessToResearch Lab(): A method that indicates whether the instructor has access to the research lab. Return true if the research topic is set; false otherwise. Write a tester program Task2Tester to test Student2 and Instructor classes you have written in Question 2.

Step by Step Solution

3.55 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Question 1 Answer Below is an implementation of the Student class as described followed by a simple tester program named Task1Tester import javautilArrayList class Student private String name private ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!