Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public class Osoba implements Comparable<Osoba>
  2. {
  3. private String name;
  4. private String surname;
  5. private String nip;
  6. private kraj country;
  7.  
  8. public Osoba(String name, String surname, String nip, kraj country)
  9. {
  10. this.name = name;
  11. this.surname = surname;
  12. this.nip = nip;
  13. this.country = country;
  14. }
  15.  
  16. @Override
  17. public int compareTo(Osoba o)
  18. {
  19. String tocompare = o.getsurname();
  20. if (this.surname.equalsIgnoreCase(tocompare))
  21. {
  22. return 0;
  23. }
  24. else
  25. {
  26. if (this.surname.compareTo(tocompare) == -1)
  27. {
  28. return -1;
  29. } else
  30. {
  31. return 1;
  32. }
  33. }
  34. }
  35.  
  36. @Override
  37. public String toString()
  38. {
  39. return this.nip + " " +this.surname+ " " + this.name;
  40. }
  41.  
  42. public String getsurname()
  43. {
  44. return surname;
  45. }
  46.  
  47. }
  48.  
  49. 6438088470 Mcpherson Jemima
  50. 4728926902 Mcpherson Neville
  51. 8093413641 Ballard Neville
  52. 8485620409 Mcpherson Neville
  53. 6118892423 Ballard Fallon
  54. 3110453986 Ballard Sybill
  55. 3338278297 Mcpherson Sybill
  56. 2797735926 Mcpherson Todd
  57. 7473716746 Mcpherson Evelyn
  58. 9519145537 Mcpherson Ima
  59. After sorting:
  60. 6438088470 Mcpherson Jemima
  61. 4728926902 Mcpherson Neville
  62. 8093413641 Ballard Neville
  63. 8485620409 Mcpherson Neville
  64. 6118892423 Ballard Fallon
  65. 3110453986 Ballard Sybill
  66. 3338278297 Mcpherson Sybill
  67. 2797735926 Mcpherson Todd
  68. 7473716746 Mcpherson Evelyn
  69. 9519145537 Mcpherson Ima
  70.  
  71. if (this.surname.compareTo(tocompare) == -1)
  72.  
  73. if (this.surname.compareTo(tocompare) < 0)
  74.  
  75. @Override
  76. public int compareTo(Osoba o)
  77. {
  78. return this.surname.compareToIgnoreCase(tocompare.getsurname()));
  79. }
  80.  
  81. @Override
  82. public int compareTo(Osoba o)
  83. {
  84. if (!this.surname.equalsIgnoreCase(o.getSurname()))
  85. {
  86. return this.surname.compareToIngoreCase(o.getSurname());
  87. }
  88. else
  89. {
  90. return this.name.compareToIngoreCase(o.getName());
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement