import java.u l.
Scanner;
public class TestMyPoint {
public sta c void main(String[] args) {
Scanner sc = new Scanner([Link]);
MyPoint p1 = new MyPoint();
[Link]("Default point p1: " + p1);
[Link]("Enter coordinates of point p2 (x y): ");
int x2 = [Link]();
int y2 = [Link]();
MyPoint p2 = new MyPoint(x2, y2);
[Link]("p2: " + p2);
[Link]("Enter new coordinates for p1 (x y): ");
int x1 = [Link]();
int y1 = [Link]();
[Link](x1, y1);
[Link]("p1 a er setXY: " + p1);
int[] coords = [Link]();
[Link]("p1 coordinates: x = " + coords[0] + ", y = " + coords[1]);
[Link]("\n--- Distance Calcula ons ---");
[Link]("Distance from p2 to origin: " + [Link]());
[Link]("Distance from p2 to p1: " + [Link](p1));
[Link]("Distance from p1 to (0,0): " + [Link]());
[Link]("Distance from p1 to (3,4): " + [Link](3, 4));
[Link]();
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 int getX() { return x; }
public int getY() { return y; }
public void setX(int x) { this.x = x; }
public void setY(int y) { 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) {
int dx = this.x - another.x;
int dy = this.y - another.y;
return [Link](dx * dx + dy * dy);
}
public double distance() {
return [Link](x * x + y * y);
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.
import java.u [Link];
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) {
[Link] = width;
[Link] = height;
@Override
public void resizeWidth(int width) {
[Link] = width;
@Override
public void resizeHeight(int height) {
[Link] = height;
public void display() {
[Link]("Rectangle width: " + width);
[Link]("Rectangle height: " + height);
[Link]("Area: " + (width * height));
public class Resize {
public sta c void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter ini al width of rectangle: ");
int width = [Link]();
[Link]("Enter ini al height of rectangle: ");
int height = [Link]();
Rectangle rect = new Rectangle(width, height);
[Link]("\nIni al Rectangle:");
[Link]();
[Link]("\nEnter new width: ");
int newWidth = [Link]();
[Link](newWidth);
[Link]("Enter new height: ");
int newHeight = [Link]();
[Link](newHeight);
[Link]("\nResized Rectangle:");
[Link]();
[Link]();