Refine the weight max and its drawing.
[Persons_Comparator.git] / src / Weight.java
CommitLineData
5687dc10 1public class Weight {
2bb2aa17 2 private int min = 2;
dcde664f 3 private int max = 250;
2bb2aa17 4 private int defaultWeight = 72;
97491195
JB
5 private int weight;
6
b974e749
JB
7 Weight() {
8 }
9
97491195
JB
10 Weight(int weight) {
11 setWeight(weight);
12 }
13
2bb2aa17
JB
14 public int getMin() {
15 return min;
16 }
17
18 public int getMax() {
19 return max;
20 }
21
22 public int getDefaultWeight() {
23 return defaultWeight;
24 }
25
97491195
JB
26 public int getWeight() {
27 return weight;
28 }
29
30 public void setWeight(int weight) {
31 if (validateWeight(weight)) {
32 this.weight = weight;
bcdec887 33 } else {
2bb2aa17 34 throw new IllegalArgumentException("Weight must be between " + this.getMin() + " and " + this.getMax());
bcdec887 35 }
97491195
JB
36 }
37
38 private boolean validateWeight(int weight) {
2bb2aa17
JB
39 return (weight >= getMin() && weight <= getMax());
40 }
41
42 public Integer[] getValuesArray() {
43 int arrayLength = this.getMax() - this.getMin() + 1;
44 Integer[] intArray = new Integer[arrayLength];
45 for (int i = 0; i < intArray.length; i++) {
46 intArray[i] = this.getMin() + i;
47 }
48 return intArray;
97491195 49 }
1c118933 50
5687dc10 51 public int distanceTo(Weight weight) {
62e26730 52 int distance = weight.getWeight() - this.getWeight();
5687dc10 53 return Math.abs(distance);
1c118933 54 }
97491195 55}