}
private boolean validateSize(int size) {
- return (size >= min && size <= max);
+ return (size >= getMin() && size <= getMax());
}
@Override
SizeView(Size sizeObj) {
setSizeObj(sizeObj);
this.label = new JLabel();
- this.label.setText("Size");
+ this.label.setText("Size (meters)");
SpinnerNumberModel numberModel = new SpinnerNumberModel((this.getSizeObj().getMax() - this.getSizeObj().getMin()) / 2,
this.getSizeObj().getMin(),
this.getSizeObj().getMax(),
this.spinner = new JSpinner(numberModel);
if (this.getSizeObj().getSize() != 0)
this.spinner.setValue(this.getSizeObj().getSize());
-
add(label);
add(spinner);
}
public class Weight implements Comparable<Weight> {
+ private int min = 2;
+ private int max = 600;
+ private int defaultWeight = 72;
private int weight;
Weight() {
setWeight(weight);
}
+ public int getMin() {
+ return min;
+ }
+
+ public int getMax() {
+ return max;
+ }
+
+ public int getDefaultWeight() {
+ return defaultWeight;
+ }
+
public int getWeight() {
return weight;
}
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 class WeightView extends JPanel {
private Weight weightObj;
private JLabel label;
+ private JComboBox<Integer> comboBox;
WeightView(Weight weightObj) {
setWeightObj(weightObj);
this.label = new JLabel();
- this.label.setText("Weight");
+ this.label.setText("Weight (kilograms)");
+ this.comboBox = new JComboBox<>(this.getWeightObj().getValuesArray());
+ if (this.getWeightObj().getWeight() != 0)
+ this.comboBox.setSelectedItem(this.getWeightObj().getWeight());
+ else
+ this.comboBox.setSelectedItem(this.getWeightObj().getDefaultWeight());
add(label);
+ add(comboBox);
}
public Weight getWeightObj() {