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