mirror of
https://github.com/Manoj-HV30/OOPS-lab-codes.git
synced 2026-05-16 19:35:25 +00:00
58 lines
1.6 KiB
Java
58 lines
1.6 KiB
Java
import java.util.Scanner;
|
|
|
|
public class TestMyPoint {
|
|
|
|
public static void main(String[] args) {
|
|
Scanner sc = new Scanner(System.in);
|
|
|
|
// Test default constructor
|
|
MyPoint p1 = new MyPoint();
|
|
System.out.println("p1: " + p1);
|
|
|
|
// Test overloaded constructor
|
|
System.out.print("Enter x coordinate: ");
|
|
int x = sc.nextInt();
|
|
System.out.print("Enter y coordinate: ");
|
|
int y = sc.nextInt();
|
|
|
|
MyPoint p2 = new MyPoint(x, y);
|
|
System.out.println("p2: " + p2);
|
|
|
|
// Test setXY()
|
|
System.out.print("Enter new x for p1: ");
|
|
int x1 = sc.nextInt();
|
|
System.out.print("Enter new y for p1: ");
|
|
int y1 = sc.nextInt();
|
|
|
|
p1.setXY(x1, y1);
|
|
System.out.println("Updated p1: " + p1);
|
|
|
|
// Test getXY()
|
|
int[] coords = p1.getXY();
|
|
System.out.println("getXY(): (" + coords[0] + ", " + coords[1] + ")");
|
|
|
|
// Test distance() to origin
|
|
System.out.println("Distance from p1 to origin: " + p1.distance());
|
|
|
|
// Test distance(int x, int y)
|
|
System.out.print("Enter x of another point: ");
|
|
int x2 = sc.nextInt();
|
|
System.out.print("Enter y of another point: ");
|
|
int y2 = sc.nextInt();
|
|
|
|
System.out.println(
|
|
"Distance from p1 to (" +
|
|
x2 +
|
|
", " +
|
|
y2 +
|
|
"): " +
|
|
p1.distance(x2, y2)
|
|
);
|
|
|
|
// Test distance(MyPoint another)
|
|
System.out.println("Distance from p1 to p2: " + p1.distance(p2));
|
|
|
|
sc.close();
|
|
}
|
|
}
|