Write a Point class to represent a point in two-dimensional
Cartesian space. The point class should support the following
methods.
You can use the following class to test your point.
import csbsju.cs160.*; public class PointTest { public static void main(String[] args) { Point origin = new Point(); Point pt = new Point(3, 4); IO.println(pt.distanceTo(origin)); // prints ``5.0'' pt.translate(2, 8); IO.println(pt.distanceTo(origin)); // prints ``13.0'' } }
public class Point { private double my_x; private double my_y; public Point() { my_x = 0.0; my_y = 0.0; } public Point(double x, double y) { my_x = x; my_y = y; } public double distanceTo(Point other) { return Math.sqrt(Math.pow(my_x - other.my_x, 2.0) + Math.pow(my_y - other.my_y, 2.0)); } public void translate(double dx, double dy) { my_x += dx; my_y += dy; } }