Implement some compareTo() methods.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 8 Jan 2019 14:30:47 +0000 (15:30 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 8 Jan 2019 14:30:47 +0000 (15:30 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/Origin.java
src/Person.java
src/Size.java
src/Weight.java

index 60e7fc9e641a40a6690458dffa0e1f8395469f59..30efb81c140862718dbe20c013629886a25f58a9 100644 (file)
@@ -1,8 +1,18 @@
 public class Origin implements Comparable<Origin> {
+    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() {
index 387e921dc72689881b21f329e828b242e17ed306..f0e5c6bc58fd5f3c8e24de2692e854b80ee96e97 100644 (file)
@@ -53,6 +53,8 @@ public class Person extends JPanel implements Comparable<Person> {
 
     @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());
     }
 }
index a526fab6a01a3fb9ce5d5ce31b5f39aef3d3bae2..20e96f6b47f04c7c9e330aec7a271e4b54aad289 100644 (file)
@@ -27,6 +27,11 @@ public class Size implements Comparable<Size> {
 
     @Override
     public int compareTo(Size size) {
-        return 0;
+        int distance = size.size - this.getSize();
+        if (distance >= 0)
+            return distance;
+        else
+            return -distance;
+
     }
 }
index b0264faa591187841e4345f0a94b00e0d9347f63..e79d1025a9e35977344ab5003e129df1aa88ff03 100644 (file)
@@ -23,6 +23,10 @@ public class Weight implements Comparable<Weight> {
 
     @Override
     public int compareTo(Weight weight) {
-        return 0;
+        int distance = weight.weight - this.getWeight();
+        if (distance >= 0)
+            return distance;
+        else
+            return -distance;
     }
 }