CJCoding With Joseph
15free / daySign inCreate account

Contact already says it implements Comparable<Contact>, but the method that interface requires is missing, so the class does not compile yet. Write compareTo so that sorting puts contacts in phone-book order.

Requirements: 1. compareTo(Contact other) orders contacts by lastName, alphabetically. 2. When two last names are equal, the firstName decides, alphabetically. 3. Return a negative number when this contact comes first, a positive number when it comes after, and zero only when both names match. 4. String already has a compareTo method that orders text alphabetically. Use it and do not compare characters yourself. 5. Do not change the fields, the constructor or toString().

Do NOT write a main method.

Expected output

Adams, Ravi
Baker, Lena
Stone, Alex
Stone, Mina

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
InterfacesClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.