parent
8b56c28004
commit
560c591a5e
@ -0,0 +1,57 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue