RESIZE H x W JAVA

Develop a JAVA program to create an interface Resizable with methods resizeWidth(int width) and resizeHeight(int height) that allow an object to be resized. Create a class Rectangle that implements the Resizable interface and implements the resize methods


PROGRAM:

 package jo;

        interface Resizable {

              void resizeWidth(int width);

              void resizeHeight(int height);

              }

              class Rectangle implements Resizable {

              private int width;

              private int height;

              public Rectangle(int width, int height) {

              this.width = width;

              this.height = height;

              }

              @Override

              public void resizeWidth(int newWidth) {

              width = newWidth;

              }

              @Override 

              public void resizeHeight(int newHeight) {

              height = newHeight;

              }

              public void display() {

              System.out.println("Rectangle Width: " + width);

              System.out.println("Rectangle Height: " + height);

              }

              }

              class TestResizable {

              public static void main(String[] args) {

              Rectangle rectangle = new Rectangle(15, 10);

              System.out.println("Original Rectangle:");

              rectangle.display();

              // Resize the rectangle

              rectangle.resizeWidth(7);

              rectangle.resizeHeight(15);

              System.out.println("Resized Rectangle:");

              rectangle.display();

              }

              }

OUTPUT:

NOTE:













No comments:

Post a Comment