public class Vector2D {
    // Cartesian coordinates
    private double x, y;

    public Vector2D (double x, double y) {
        this.x = x;
        this.y = y;
    }
    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public Vector2D plus(Vector2D v) {
        if (v != null) {
            return new Vector2D(getX() + v.x, getY() + v.y);
        }
        else {
            return new Vector2D(getX(), getY());
        }
    }

    public Vector2D times(double scalar) {
        return new Vector2D(getX() * scalar, getY() * scalar);
    }

    public Vector2D rotate(double degree) {
        double radAngle = Math.PI * degree / 180;
        return new Vector2D(x * Math.cos(radAngle) + y * Math.sin(radAngle), - x * Math.sin(radAngle) - y * Math.cos(radAngle));
    }

    public String getDescription(){
        return "x,\ty";
    }

    public String toString(){
        return String.format("%.3f,\t%.3f", x, y);
    }
}

