From: Jérôme Benoit Date: Tue, 8 Jan 2019 14:30:47 +0000 (+0100) Subject: Implement some compareTo() methods. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=613054ac3144a04ab284e159b610317eacf67e1f;p=Persons_Comparator.git Implement some compareTo() methods. Signed-off-by: Jérôme Benoit --- diff --git a/src/Origin.java b/src/Origin.java index 60e7fc9..30efb81 100644 --- a/src/Origin.java +++ b/src/Origin.java @@ -1,8 +1,18 @@ public class Origin implements Comparable { + private String continent; private String country; - Origin(String country) { + Origin(String continent, String country) { setCountry(country); + setContinent(continent); + } + + public String getContinent() { + return continent; + } + + public void setContinent(String continent) { + this.continent = continent; } public String getCountry() { diff --git a/src/Person.java b/src/Person.java index 387e921..f0e5c6b 100644 --- a/src/Person.java +++ b/src/Person.java @@ -53,6 +53,8 @@ public class Person extends JPanel implements Comparable { @Override public int compareTo(Person person) { - return 0; + return this.firstname.compareTo(person.getFirstname()) + this.origin.compareTo(person.getOrigin()) + + this.size.compareTo(person.getPersonSize()) + this.weight.compareTo(person.getWeight()) + + this.eye.compareTo(person.getEye()); } } diff --git a/src/Size.java b/src/Size.java index a526fab..20e96f6 100644 --- a/src/Size.java +++ b/src/Size.java @@ -27,6 +27,11 @@ public class Size implements Comparable { @Override public int compareTo(Size size) { - return 0; + int distance = size.size - this.getSize(); + if (distance >= 0) + return distance; + else + return -distance; + } } diff --git a/src/Weight.java b/src/Weight.java index b0264fa..e79d102 100644 --- a/src/Weight.java +++ b/src/Weight.java @@ -23,6 +23,10 @@ public class Weight implements Comparable { @Override public int compareTo(Weight weight) { - return 0; + int distance = weight.weight - this.getWeight(); + if (distance >= 0) + return distance; + else + return -distance; } }