From 613054ac3144a04ab284e159b610317eacf67e1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Jan 2019 15:30:47 +0100 Subject: [PATCH] Implement some compareTo() methods. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/Origin.java | 12 +++++++++++- src/Person.java | 4 +++- src/Size.java | 7 ++++++- src/Weight.java | 6 +++++- 4 files changed, 25 insertions(+), 4 deletions(-) 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; } } -- 2.34.1