X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FWeight.java;h=4b67611af0eef2f07bfa7437e498d9418298af7c;hb=2bb2aa17b6533b2e8d2fc97997ed76bc38b6931d;hp=b0264faa591187841e4345f0a94b00e0d9347f63;hpb=1c1189337121a1baa74961813e619c99b398a333;p=Persons_Comparator.git diff --git a/src/Weight.java b/src/Weight.java index b0264fa..4b67611 100644 --- a/src/Weight.java +++ b/src/Weight.java @@ -1,10 +1,28 @@ public class Weight implements Comparable { + private int min = 2; + private int max = 600; + private int defaultWeight = 72; private int weight; + Weight() { + } + Weight(int weight) { setWeight(weight); } + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + + public int getDefaultWeight() { + return defaultWeight; + } + public int getWeight() { return weight; } @@ -13,16 +31,29 @@ public class Weight implements Comparable { if (validateWeight(weight)) { this.weight = weight; } else { - throw new IllegalArgumentException("Weight cannot be negative or zero"); + throw new IllegalArgumentException("Weight must be between " + this.getMin() + " and " + this.getMax()); } } private boolean validateWeight(int weight) { - return (weight > 0); + return (weight >= getMin() && weight <= getMax()); + } + + public Integer[] getValuesArray() { + int arrayLength = this.getMax() - this.getMin() + 1; + Integer[] intArray = new Integer[arrayLength]; + for (int i = 0; i < intArray.length; i++) { + intArray[i] = this.getMin() + i; + } + return intArray; } @Override public int compareTo(Weight weight) { - return 0; + int distance = weight.getWeight() - this.getWeight(); + if (distance >= 0) + return distance; + else + return -distance; } }