public class Point {
Point p1, p2;
int x, y;
public Point(int a, int b) {
this.x = a;
this.y = b;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public double distanceTo(Point p) {
//where my equation would go
double lengthA = (double)(this.getX() - p.getX());
double lengthB = (double)(this.getY() - p.getY());
double distance = 0.0;
//FINISH FORMULA
return distance;
}
public static void main(String[] args) {
Point p1 = new Point(3,4);
Point p2 = new Point(16,-6);
double distance = p1.distanceTo(p2);
System.out.print(distance); //just to test
}
}
I changed your distanceTo formula to access points how you looked like you wanted to.
since you called it with p1, when inside your method "this" refers to object p1.
since you pass it p2, use p2 by name to access its getter methods to.
they both have ints, and to keep precision you want to cast/change(?I forget if it is called casting with primitive types) it from into to double.
note: you will need to use the Math class to fix your formula for distance