001package types.point4; 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} 046public class Main { 047 private Main() {} 048 public static void main(String[] args) { 049 CartesianPoint p1 = new CartesianPoint(0,0,Color.RED); 050 CartesianPoint q1 = new CartesianPoint(1,1,Color.BLUE); 051 PolarPoint r1 = new PolarPoint(0,0,Color.RED); 052 053 Point p2 = p1; 054 Point q2 = q1; 055 Point r2 = r1; 056 057 Colored p3 = p1; 058 Colored q3 = q1; 059 Colored r3 = r1; 060 } 061}