You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.2 KiB
57 lines
1.2 KiB
public class Square implements Shape, Resizable {
|
|
private double side;
|
|
private String color;
|
|
|
|
public Square(double side, String color) {
|
|
this.side = side;
|
|
this.color = color;
|
|
}
|
|
|
|
@Override
|
|
public double calculateArea() {
|
|
return side * side;
|
|
}
|
|
|
|
@Override
|
|
public double calculatePerimeter() {
|
|
return 4 * side;
|
|
}
|
|
|
|
@Override
|
|
public String getColor() {
|
|
return color;
|
|
}
|
|
|
|
@Override
|
|
public void setColor(String color) {
|
|
this.color = color;
|
|
}
|
|
|
|
public double getSide() {
|
|
return side;
|
|
}
|
|
|
|
public void setSide(double side) {
|
|
this.side = side;
|
|
}
|
|
|
|
@Override
|
|
public void resize(double factor) {
|
|
if (factor <= 0) {
|
|
throw new IllegalArgumentException("Resize factor must be positive");
|
|
}
|
|
this.side *= factor;
|
|
}
|
|
|
|
@Override
|
|
public void resizeWidth(double factor) {
|
|
// For square, resizing width also resizes height to maintain square property
|
|
resize(factor);
|
|
}
|
|
|
|
@Override
|
|
public void resizeHeight(double factor) {
|
|
// For square, resizing height also resizes width to maintain square property
|
|
resize(factor);
|
|
}
|
|
} |