class Inter { public static void main(String[] args) { CartesianPoint cp = new CartesianPoint(3, 4); System.out.println("cp.x() == " + cp.x()); System.out.println("cp.y() == " + cp.y()); System.out.println("cp.r() == " + cp.r()); System.out.println("cp.theta() == " + cp.theta()); System.out.println(); PolarPoint pp = new PolarPoint(5, Math.atan2(4, 3)); System.out.println("pp.x() == " + pp.x()); System.out.println("pp.y() == " + pp.y()); System.out.println("pp.r() == " + pp.r()); System.out.println("pp.theta() == " + pp.theta()); System.exit(0); } }; interface Point { double x(); double y(); double r(); double theta(); }; class CartesianPoint implements Point { private double _x; private double _y; CartesianPoint(double _x, double _y) { this._x = _x; this._y = _y; } @Override public double x() { return _x; } @Override public double y() { return _y; } @Override public double r() { return Math.hypot(_x, _y); } @Override public double theta() { return Math.atan2(_y, _x); } }; class PolarPoint implements Point { private double _r; private double _theta; PolarPoint(double _r, double _theta) { this._r = _r; this._theta = _theta; } @Override public double x() { return _r * Math.cos(_theta); } @Override public double y() { return _r * Math.sin(_theta); } @Override public double r() { return _r; } @Override public double theta() { return _theta; } };