Kind Regards Chapinch[color="#ff0000"][color="#ff0000"]
import java.util. *;public class AddressBook
{
private List
public static void main(String[] args)
{
AddressBook book = new AddressBook();
}
public AddressBook()
{
super();
this.addNewMember();
}
public List
{
return this.members;
}
public void addNewMember()
{
String text = null;
while(!text.equals("."))
{
Scanner scan = new Scanner(System.in);
text = scan.nextLine();
Person newMember = new Person(text);
this.getMembers().add(newMember);
}
this.sortAddressBook();
}
public void sortAddressBook()
{
Collections.sort(this.getMembers());
System.out.println(this.getMembers());
}
}
import java.util.Comparator;
public class Person implements Comparable
{
private String name;
public String getName()
{
return name;
}
public Person(String name)
{
this.name = name;
}
public int compareTo(Person arg)
{
return this.getName().compareTo(arg.getName());
}
}
[color="#ff0000"][color="#ff0000"]
[color="#ff0000"][color="#ff0000"][color="#7f0055"][color="#7f0055"]