0% found this document useful (0 votes)
16 views4 pages

Program 7

The document provides step-by-step instructions to create a JAVA program that implements a Resizable interface with methods to resize width and height. It details the creation of a Rectangle class that implements this interface, along with the necessary code and how to run the program in Eclipse IDE. The expected output confirms the successful execution of the program, demonstrating the use of interfaces in Java.

Uploaded by

samfrancisco069
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Program 7

The document provides step-by-step instructions to create a JAVA program that implements a Resizable interface with methods to resize width and height. It details the creation of a Rectangle class that implements this interface, along with the necessary code and how to run the program in Eclipse IDE. The expected output confirms the successful execution of the program, demonstrating the use of interfaces in Java.

Uploaded by

samfrancisco069
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM 7:

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
Here are clear step-by-step instructions to perform this experiment in
Eclipse IDE, along with the corrected error-free code.

How to Perform This Experiment in Eclipse IDE

Follow these steps exactly:

Open Eclipse IDE

• Open Eclipse.

• Click File → New → Java Project.

• Enter project name: ResizableDemo

• Click Finish.

Create a Package

• Right-click on src → New → Package

• Enter name:

• employee

• Click Finish.

Create Interface File: [Link]


• Right-click on the package employee

• Select New → Interface

• Name it:

• Resizable

• Paste this code:


package employee;
interface Resizable {

void resizeWidth(int width);

void resizeHeight(int height);


}

Create Class File: [Link]

• Right-click on package employee → New → Class

• Name it:

• Rectangle

• Paste this code (error-free):


package employee;

class Rectangle implements Resizable {

private int width;

private int height;

public Rectangle(int width, int height) {

[Link] = width;
[Link] = height;

public void resizeWidth(int width) {

[Link] = width;

public void resizeHeight(int height) {

[Link] = height;
}
public void printSize() {

[Link]("Width: " + width + ", Height: " + height);

}
}

Create Main Class: [Link]

• Right-click on package employee → New → Class

• Name it:

• Point

• Check public static void main(String[] args)


• Paste this corrected code:
package employee;

public class Point {

public static void main(String[] args) {

Rectangle rectangle = new Rectangle(100, 150);

[Link]();

[Link](150);

[Link](200);

[Link]();

Run the Program

• Right-click on [Link]
• Click Run As → Java Application
Expected Output (as given)

Width: 100, Height: 150

Width: 150, Height: 200

RESULT

The Java program demonstrating the use of interfaces was successfully created and executed
in Eclipse IDE, and the output was verified.

You might also like