Combination



examples/shapes/Point.java
public class Point {
    private int x;
    private int y;

    public Point(int a, int b) {
        x = a;
        y = b;
    }

    public String showCoord() {
        return "(" + x + ", " + y + ")";
    }

    public void move(int dx, int dy) {
        x += dx;
        y += dy;
    }

    public int getx() {
        return x;
    }
    public int gety() {
        return y;
    }
}

examples/shapes/Line.java
import java.lang.Math;

public class Line {
    private Point a;
    private Point b;

    public Line(Point aa, Point bb) {
        a = aa;
        b = bb;
    }

    public String showLine() {
        return a.showCoord() + "___" + b.showCoord();
    }

    public double length() {
        return Math.pow(Math.pow(a.getx()-b.getx(), 2) + Math.pow(a.gety()-b.gety(), 2), 0.5);
    }
}

examples/shapes/RunCode.java
public class RunCode {
    public static void main(String[] args) {
        System.out.println("Hello");
        Point p1 = new Point(2, 3);
        System.out.println(p1);
        // System.out.println(p1.x);  //  x has private access in Point
        System.out.println(p1.showCoord());
        p1.move(3, 7);
        System.out.println(p1.showCoord());

        Point p2 = new Point(2, 6);
        System.out.println(p2.showCoord());

        Line line = new Line(p1, p2);
        System.out.println(line.showLine());
        System.out.println(line.length());
    }
}