interface Resizable {
void resizeWidth(int width);
void resizeHeight(int height);
}
class Rectangle implements Resizable {
private int width;
private int height;
// Constructor
public Rectangle(int width, int height) {
[Link] = width;
[Link] = height;
}
// Method to resize the width
@Override
public void resizeWidth(int width) {
if (width > 0) {
[Link] = width;
[Link]("Width resized to: " + [Link]);
} else {
[Link]("Width must be greater than 0.");
}
}
// Method to resize the height
@Override
public void resizeHeight(int height) {
if (height > 0) {
[Link] = height;
[Link]("Height resized to: " + [Link]);
} else {
[Link]("Height must be greater than 0.");
}
}
// Method to display rectangle dimensions
public void displayDimensions() {
[Link]("Rectangle Dimensions - Width: " + width + ", Height: "
+ height);
}
}
public class MainClass {
public static void main(String[] args) {
// Create a Rectangle object
Rectangle rectangle = new Rectangle(10, 20);
[Link]();
// Resize the width and height
[Link](30);
[Link](40);
[Link]();
// Test invalid resize
[Link](-5);
[Link](0);
[Link]();
}
}