Question
Needs to be written in Java. The necessary class wil be included below this import java.util.*; public class SortPerson { private ArrayList people = new
Needs to be written in Java. The necessary class wil be included below this
import java.util.*;
public class SortPerson
{
private ArrayList
public SortPerson()
{
people.add(new Person(301, "Albert Einstein", "123 My Street", "Your Town", "UT", "123-4567"));
people.add(new Person(860, "John Smith", "867 Elm St.", "Lake Forest", "AZ", "555-6543"));
people.add(new Person(51, "Cranston Snort", "1600 Pennsylvania Ave", "Washington", "DC", "1-800-123-4783"));
people.add(new Person(602, "Fred Wally", "123 E. Wilson", "Sunset", "UT", "678-4351"));
people.add(new Person(857, "Isaac Newton", "1234 W. 900 S.", "Salt Lake City", "UT", "563-4567"));
people.add(new Person(403, "Wilson", "1492 USA Way", "Morristown", "NJ", "345-8765"));
people.add(new Person(4567, "John Smith", "417 El Toro", "Irvine", "CA", "869-3482"));
}
public void sortByName(String name)
{
// sort list people by name here
____________________________________
for (Person p : people) // print sorted list
System.out.println(p);
System.out.println(" Searching for:");
// make key based on search name
__________________________________________
// add natural (by name in this case) search code here
__________________________________________
if (index >= 0)
System.out.println(people.get(index));
else
System.out.println(name + " was not found");
System.out.println(); // print a blank line
}
public void sortByID(int id)
{
// make a int-based compartor here
____________________________________
// sort list people by id here
____________________________________
for (Person p : people) // print sorted list
System.out.println(p);
System.out.println(" Searching for:");
// make key based on id
_____________________________________
// add comparator-based search code here
if (index >= 0)
System.out.println(people.get(index));
else
System.out.println(id + " was not found");
}
public static void main(String args[])
{
SortPerson sp = new SortPerson();
sp.sortByName(args[0]);
sp.sortByID(Integer.parseInt(args[1]));
}
}
Assignment Follow the Widget / WareHouse example program. 1. Create a public class Person that implements the Comparable interface Instance Variables 1. private int id; 11. private String name: 111. private String street: 1V. private String city: V. private String state: V1. private String phoneNumber: a b. Constructors: i. public Person (int num, String n, String s, String c, String st, String p) ii. public Person (String n) (initialize the name and sets the other values to null or 0 as appropriate) iii. public Person (int n) (initialize the id number and sets the other values to null) c. Methods i. public String tostring ) (which concatenates all Person instance variables) ii. public int getID ) (accessor method for the id instance variable) The Comparable Interface i. Comparable is a generic interface (as of Java 5): ComparableStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started