//******************************************************************** // Contact.java // // Rappresenta un contatto telefonico. //******************************************************************** class Contact implements Comparable { private String firstName, lastName, phone; //----------------------------------------------------------------- // Nuovo contatto con le informazioni specificate. //----------------------------------------------------------------- public Contact (String firstName, String lastName, String phone) { this.firstName = firstName; this.lastName = lastName; this.phone = phone; } //----------------------------------------------------------------- // Riporta la descriuzione del contatto come stringa di caratteri. //----------------------------------------------------------------- public String toString () { return lastName + ", " + firstName + "\t" + phone; } //----------------------------------------------------------------- // Usa il cognome e il nome per determinare l'ordine alfabetico. //----------------------------------------------------------------- public int compareTo (Object other) { int result; if (lastName.equals(((Contact)other).lastName)) result = firstName.compareTo(((Contact)other).firstName); else result = lastName.compareTo(((Contact)other).lastName); return result; } }