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.

21 lines
515 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package jinjieti;
import jichuti.Square;
/**
* 可缩放的正方形实现Shape和Resizable
*/
public class ResizableSquare extends Square implements Resizable {
public ResizableSquare(String color, double side) {
super(color, side);
}
@Override
public void resize(double factor) {
if (factor <= 0) {
throw new IllegalArgumentException("缩放因子必须为正数");
}
setSide(getSide() * factor); // 调整边长
}
}