Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Osoba implements Comparable<Osoba>
- {
- private String name;
- private String surname;
- private String nip;
- private kraj country;
- public Osoba(String name, String surname, String nip, kraj country)
- {
- this.name = name;
- this.surname = surname;
- this.nip = nip;
- this.country = country;
- }
- @Override
- public int compareTo(Osoba o)
- {
- String tocompare = o.getsurname();
- if (this.surname.equalsIgnoreCase(tocompare))
- {
- return 0;
- }
- else
- {
- if (this.surname.compareTo(tocompare) == -1)
- {
- return -1;
- } else
- {
- return 1;
- }
- }
- }
- @Override
- public String toString()
- {
- return this.nip + " " +this.surname+ " " + this.name;
- }
- public String getsurname()
- {
- return surname;
- }
- }
- 6438088470 Mcpherson Jemima
- 4728926902 Mcpherson Neville
- 8093413641 Ballard Neville
- 8485620409 Mcpherson Neville
- 6118892423 Ballard Fallon
- 3110453986 Ballard Sybill
- 3338278297 Mcpherson Sybill
- 2797735926 Mcpherson Todd
- 7473716746 Mcpherson Evelyn
- 9519145537 Mcpherson Ima
- After sorting:
- 6438088470 Mcpherson Jemima
- 4728926902 Mcpherson Neville
- 8093413641 Ballard Neville
- 8485620409 Mcpherson Neville
- 6118892423 Ballard Fallon
- 3110453986 Ballard Sybill
- 3338278297 Mcpherson Sybill
- 2797735926 Mcpherson Todd
- 7473716746 Mcpherson Evelyn
- 9519145537 Mcpherson Ima
- if (this.surname.compareTo(tocompare) == -1)
- if (this.surname.compareTo(tocompare) < 0)
- @Override
- public int compareTo(Osoba o)
- {
- return this.surname.compareToIgnoreCase(tocompare.getsurname()));
- }
- @Override
- public int compareTo(Osoba o)
- {
- if (!this.surname.equalsIgnoreCase(o.getSurname()))
- {
- return this.surname.compareToIngoreCase(o.getSurname());
- }
- else
- {
- return this.name.compareToIngoreCase(o.getName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement