Advertisement
Guest User

Untitled

a guest
May 24th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. abstract class Person implements Comparable<Person> {
  2. protected String lastName, firstName;
  3.  
  4. public Person(String lastName, String firstName) {
  5. this.lastName = lastName;
  6. this.firstName = firstName;
  7. }
  8.  
  9. public String fullName() { return firstName+" "+lastName; }
  10.  
  11. protected abstract int rank();
  12.  
  13. public compareTo(Person o) {
  14. int r1 = this.rank(), r2 = o.rank();
  15. return r1 != r2 ? r1-r2 : this.fullName().compareTo(o.fullName());
  16. }
  17. }
  18.  
  19. class Instructor extends Person {
  20. protected int rank() { return 5; }
  21. }
  22.  
  23. class TeachingAssistant extends Person {
  24. protected int rank() { return 10; }
  25. }
  26.  
  27. class Student extends Person {
  28. protected int rank() { return 15; }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement