package com.java1.day14;
public class DrawShape {
public static void main(String[] args) {
PointEx[] p = { new PointEx(100, 100),
new PointEx(140, 150),
new PointEx(200, 100)
};
Triangle t = new Triangle(p);
Circle c = new Circle(new PointEx(150, 150), 50);
t.draw();
c.draw();
}
}
class Shape {
String color = "black";
void draw() {
System.out.printf("[color=%s]%n", color);
}
}
class PointEx {
int x;
int y;
PointEx(int x, int y){
this.x = x;
this.y =y;
}
PointEx(){
this(0, 0);
}
String getXY() {
return "(" + x + "," + y + ")";
}
}
class Circle extends Shape {
PointEx center;
int r ;
Circle() {
this(new PointEx(0, 0), 100);
}
Circle(PointEx center, int r){
this.center = center;
this.r = r;
}
void draw() {
System.out.printf("[center=(%d, %d), r=%d, color=%s]%n", center.x, center.y, r, color);
}
}
class Triangle extends Shape {
PointEx[] p = new PointEx[3];
Triangle(PointEx[] p) {
this.p = p;
}
void draw() {
System.out.printf("[p1=%s, p2=%s, p3=%s, color=%s]%n", p[0].getXY(), p[1].getXY(), p[2].getXY(), color );
}
}
출력결과
[p1=(100,100), p2=(140,150), p3=(200,100), color=black]
[center=(150, 150), r=50, color=black]