Add an ArrayList of persons to the Person class.
[Persons_Comparator.git] / src / Weight.java
index 2a8c8127d7cb17f63cbe5aa8e6a98a26209a3f24..47547ba4f524711c42a3bc1c3e561fec0be48853 100644 (file)
@@ -1,6 +1,9 @@
-public class Weight {
+public class Weight implements Comparable<Weight> {
     private int weight;
 
+    Weight() {
+    }
+
     Weight(int weight) {
         setWeight(weight);
     }
@@ -20,4 +23,13 @@ public class Weight {
     private boolean validateWeight(int weight) {
         return (weight > 0);
     }
+
+    @Override
+    public int compareTo(Weight weight) {
+        int distance = weight.weight - this.getWeight();
+        if (distance >= 0)
+            return distance;
+        else
+            return -distance;
+    }
 }