Fix .compareTo() calculation in Size and Weight classes.
[Persons_Comparator.git] / src / Weight.java
index b0264faa591187841e4345f0a94b00e0d9347f63..5e33327fac7ec77eac23a14ec0aa46a6b4e65342 100644 (file)
@@ -1,6 +1,9 @@
 public class Weight implements Comparable<Weight> {
     private int weight;
 
+    Weight() {
+    }
+
     Weight(int weight) {
         setWeight(weight);
     }
@@ -23,6 +26,10 @@ public class Weight implements Comparable<Weight> {
 
     @Override
     public int compareTo(Weight weight) {
-        return 0;
+        int distance = weight.getWeight() - this.getWeight();
+        if (distance >= 0)
+            return distance;
+        else
+            return -distance;
     }
 }