Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Point {
- private int x, y;
- public Point() {
- this.x = 0;
- this.y = 0;
- }
- public Point(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- public int getY() {
- return y;
- }
- public void setY(int y) {
- this.y = y;
- }
- public double distance(Point anotherPoint) {
- double xCoordSq = Math.pow((x - anotherPoint.x), 2);
- double yCoordSq = Math.pow((y - anotherPoint.y), 2);
- return Math.sqrt(xCoordSq + yCoordSq);
- }
- public static void main(String[] args) {
- Point first = new Point(6, 5);
- Point second = new Point(3, 1);
- System.out.println("distance(0,0)= " + first.distance(new Point(0,0)));
- System.out.println("distance(second)= " + first.distance(second));
- System.out.println("distance(2,2)= " + first.distance(new Point(2,2)));
- Point point = new Point();
- System.out.println("distance()= " + point.distance(new Point()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment