For code1 this class which defines a persons English charact
For code1 this class which defines a person\'s (English character, Western-ordered) name. Check the code1 class and then complete the two Comparator classes: one which usable for ordering Name instances by first name and a similar one to assist in ordering by last name.
code1 class:
First Comparator class:
Solution
// FirstNameComparator.java
import java.util.Comparator;
import java.util.function.Function;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
import java.util.function.ToLongFunction;
/**
* Class which can be used to compare and order two instances of {@code Name}. Instances of this class will sort
* {@code Name} instances by people\'s first name. If two people have the same first names, we will NOT use their last
* names to break ties.
*
* @author Matthew Hertz
*/
public class FirstNameComparator implements Comparator<Name> {
public int compare(Name name1, Name name2) {
return name1.getFirstName().compareTo(name2.getFirstName());
}
}
// LastNameComparator.java
import java.util.Comparator;
/**
* Class which can be used to compare and order two instances of {@code Name}. Instances of this class will sort
* {@code Name} instances by people\'s last name. If two people have the same last names, we will NOT use their first
* names to break ties.
*
* @author Matthew Hertz
*/
public class LastNameComparator implements Comparator<Name> {
public int compare(Name name1, Name name2) {
return name1.getLastName().compareTo(name2.getLastName());
}
}
