Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a Person class (below). You may not make any changes to the Person class. Create a People class that consists of an

You are given a Person class (below). You may not make any changes to the Person class. Create a People class that consists of an ArrayList of Person objects. The only constructor for the People class takes a String representing a filename. The constructor creates and fills the ArrayList with the data in the file (Each line in the file contains a first name followed by a space then the last name. You may assume that every line has only 2 names, there are no spaces in names). Implement a toString() method. Add a sort method. This method is a member of the class (how does this change the parameter list?) and should alphabetize the list be careful, last names are not unique how will you handle this? Id suggest getting the sort working sorting only on last name, then add in the secondary (first name) sort.

Person Class

public class Person { private String firstName; /** Person's first name*/ private String lastName; /** Person's last name*/ /** Person constructor, provided a first and last name @param first first name @param last last name */ public Person(String first, String last) { firstName = first; lastName = last; } /** getFirst to return first name @return first name */ public String getFirst() { return firstName; } /** getLast to return last name @return last name */ public String getLast() { return lastName; } /** setFirst to set first name @param first first name */ public void setFirst(String first) { firstName = first; } /** setFirst to set last name @param last last name */ public void setLast(String last) { lastName = last; } /** toString returns string representation of Person object in form "First Last" @return string representation of object */ public String toString() { return firstName + " " + lastName; } /** equals determine if Persons contain same first and last name @return true if first and last name are both the same */ boolean equals(Person other) { return (lastName.equals(other.lastName) && firstName.equals(other.firstName)); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

6. Describe at least three types of servers.

Answered: 1 week ago