Created
August 10, 2012 21:25
-
-
Save imduffy15/3318135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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