Skip to content

Instantly share code, notes, and snippets.

@imduffy15
Created August 10, 2012 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imduffy15/3318135 to your computer and use it in GitHub Desktop.
Save imduffy15/3318135 to your computer and use it in GitHub Desktop.
import java.util.*;
class Person {
private String firstname;
private String secondname;
Person() {
//default constructor
}
Person(String firstname, String secondname) {
this.firstname = firstname;
this.secondname = secondname;
}
void getPerson() {
this.firstname = Console.readToken();
this.secondname = Console.readToken();
}
String putName() {
return secondname + ", " + firstname;
}
}
class PersonComparable implements Comparator<Person> {
@Override
public int compare(Person p1, Person p2) {
return p1.putName().compareTo(p2.putName());
}
}
class Ex1 {
public static void main(String[] args) {
ArrayList<Person> people = new ArrayList<Person>();
while(!Console.endOfFile()) {
Person tmp = new Person();
tmp.getPerson();
people.add(tmp);
}
Collections.sort(people, new PersonComparable());
for(Person p : people) {
System.out.println(p.putName());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment