Question: ( Classes and Methods ) For this problem you are going to build onto the existing hierarchy of Student and Address classes ( included with

(Classes and Methods) For this problem you are going to build onto the existing hierarchy of Student and Address classes (included with this assignment note that these are modified versions of the ones included in chapter 7 code).
In the academic world, a cohort is a group of students who work on a project, objective, or task together. A cohort can simply include students in the same major at a university, for example. For this problem, you are to create class Cohort, which includes a collection of Students. You are free to store the collection using any means you wish, but an ArrayList is likely the simplest. Note that any variables in Cohort must be private, to protect encapsulation. You are to write the following 5 methods for Cohort:
i. public Cohort() : a standard, default constructor it should initialize the collection of students to be empty.
ii. public void addStudent(Student newStudent) : this method is a relatively simple one, and should simply add newStudent to the collection of students in the cohort.
iii. public Student getStudentByAddressMatch(Address homeA, Address schoolA) : this method returns the first Student in the cohort whose addresses match the input values. If no Students possess the given address, the method should return null. Note that more than one student may have the same pair of addresses, in which case you should return the first matching student added to the Cohort.
iv. public Student getStudentLongestLastName() : this method should return the Student with the longest last name in terms of characters (i.e.Durbin has 6 characters, while Fernandez has 9 characters). If multiple students have an equally long last name, the last matching student added to the Cohort should be returned.
v. public String toString() : the standard toString method for the entire Cohort: in this case, it should produce a sequence of the students first and last names according to the order in which they were added to the collection, separated by new lines per student. It should not include their address information!
While not mandatory, it is highly recommended that you test your Cohort class using the included CohortDriver.java file. Your output on screen should match (or come extremely close to matching) what is provided in the file CohortDriver_output.txt.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!