public class PhoneEntry { private String first; private String last; private String phone; private String email; /* PRE: 'first' and 'last' can not both be the empty string, and * no String should be null * POST: Stores input values in class fields. */ public PhoneEntry(String first, String last, String phone, String email) { this.first = first; this.last = last; this.phone = phone; this.email = email; } /* PRE: a valid PhoneEntry (where not both 'first' and 'last' can be * empty at the same time. * POST: Phone entries will be compared as follows: * * if both have first and last name not empty, compare * the strings "last, first" * * if both have first names empty, compare last names * * if both have last names empty, compare first names * * an entry with first name only is considered smaller than * an entry with both first and last name */ // THIS CODE BELOW DOES NOT WORK AS SPECIFIED IN 'POST' !!! Change it! public int compareToIgnoreCase(PhoneEntry e) { if ((last.equals("")) || (e.last.equals(""))) { return first.compareToIgnoreCase(e.first); } else { return last.compareToIgnoreCase(e.last); } } public String getFirst() { return first; } public String getLast() { return last; } public String getPhone() { return phone; } public String getEmail() { return email; } public String toString() { if (last.equals("")) return first; else if (first.equals("")) return last; else return last + ", " + first; } }