001package types.point5;
002import java.awt.Color;
003interface Colored {
004        Color getColor();
005}
006interface Point {
007        double getX();
008        double getY();
009}
010interface ColoredPoint
011extends Colored, Point
012{ }
013final class CartesianPoint implements ColoredPoint {
014        
015        private final double x;
016        private final double y;
017        private final Color color;
018        public CartesianPoint(double x, double y, Color color) {
019                this.x = x;
020                this.y = y;
021                this.color = color;
022        }
023        public double getX() { return x; }
024        public double getY() { return y; }
025        public Color getColor() {
026                System.out.println("It's Cartesian!");
027                return color;
028        }
029        
030}
031final class PolarPoint implements ColoredPoint {
032        
033        private final double theta;
034        private final double r;
035        private final Color color;
036        public PolarPoint(double theta, double r, Color color) {
037                this.theta = theta;
038                this.r = r;
039                this.color = color;
040        }
041        public double getX() { return r*Math.cos(theta); }
042        public double getY() { return r*Math.sin(theta); }
043        public Color getColor() {
044                System.out.println("It's Polar!");
045                return color;
046        }
047        
048}
049public class Main {
050        private Main() {}
051        public static void printColoredPoint(ColoredPoint cp) {
052                System.out.println(cp.getX());
053                System.out.println(cp.getY());
054                System.out.println(cp.getColor());
055        }
056        public static void main(String[] args) {
057                printColoredPoint(new CartesianPoint(0,0,Color.RED));
058                printColoredPoint(new PolarPoint(0,0,Color.RED));
059        }
060}