A class called MyPoint, which models a 2D point with x and y coordinates, is designed as follows:
class MyPoint
private int x;
private int y;
public MyPoint()
this.x = 0;
this.y = 0;
public MyPoint(int x, int y)
this.x = x;
this.y = y;
public void setXY(int x, int y) {
this.x = x;
this.y = y;
public int[] getXY()
return new int[] { x, y };
@Override
public String toString()
return "(" + x + ", " + y + ")";
public double distance(int x, int y)
int dx = this.x -x;
int dy = this.y -y;
return [Link](dx * dx + dy * dy);
public double distance(MyPoint another)
return distance (another.x, another.y);
public double distance()
return distance(0, 0);
public int getX()
return x;
public int getY()
return y;
public class Program4
public sta c void main(String[] args)
MyPoint p1 = new MyPoint();
[Link]("Point p1: " + p1); // Should print (0, 0)
MyPoint p2 = new MyPoint(3, 4);
[Link]("Point p2: " + p2); // Should print (3, 4)
[Link](5, 6);
[Link]("A er se ng p1 to (5, 6): " + p1); // Should print (5, 6)
int[] coordinates = [Link]();
[Link]("Coordinates of p2: (" + coordinates[0] + ", " + coordinates[1] + ")"); // Should
print (3, 4)
[Link]("Distance from p1 to (1, 1): " + [Link](1, 1)); // Should print the calculated
distance
[Link]("Distance from p1 to p2: " + [Link](p2)); // Should print the calculated
distance
[Link]("Distance from p1 to origin: " + [Link]()); // Should print the calculated
distance
Develop a JAVA program to create an interface Resizable with methods resize Width(int width) and
resize Height(int height) that allow an object to be resized. Create a class Rectangle that implements
the Resizable interface and implements the resize methods.
interface Resizable
void resizeWidth(int width); // Method to resize the width
void resizeHeight(int height); // Method to resize the height
class Rectangle implements Resizable {
private int width; // Store the width of the rectangle
private int height; // Store the height of the rectangle
public Rectangle(int width, int height) {
[Link] = width;
[Link] = height;
@Override
public void resizeWidth(int width) {
[Link] = width;
[Link]("New width: " + [Link]);
@Override
public void resizeHeight(int height) {
[Link] = height;
[Link]("New height: " + [Link]);
public void displayDimensions() {
[Link]("Current dimensions -> Width: " + [Link] + ", Height: " + [Link]);
public class P7 {
public sta c void main(String[] args) { BCS306A
Rectangle rect = new Rectangle(10, 20);
[Link]();
// Resize the width and height using the implemented methods
[Link](30);
[Link](40);
// Display the updated dimensions
[Link]();
*******Output*******
Display method in outer class
Display method in inner class