package abc.tt.tt;
class Shape{
protected String name;
protected int x, y;
public Shape(String name, int x, int y) {
this.name = name;
this.x = x;
this.y = y;
}
public Shape() {
this("도형",0,0);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public void ShowInfo(){
System.out.println("===== 정보출력 ===================");
System.out.println("이름: "+name);
System.out.println("좌표(2D): "+x+", "+y);
}
}
class Circle extends Shape{
protected int radius;
public Circle(String name, int x, int y, int radius) {
super(name, x, y);
this.radius = radius;
}
public int getRadius() {
return radius;
}
public void setRadius(int radius) {
this.radius = radius;
}
public void ShowDetailInfo2D() {
ShowInfo();
System.out.println("반지름: "+radius);
}
}
class Rectangle extends Shape{
protected int width, height;
public Rectangle(String name, int x, int y, int width, int height) {
super(name, x, y);
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public void ShowDetailInfo2D() {
ShowInfo();
System.out.println("너비, 높이: "+width+", "+height);
}
}
class Sphere extends Circle{
protected int z;
public Sphere(String name, int x, int y, int z, int radius) {
super(name, x, y, radius);
this.z = z;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public void ShowDetailInfo3D() {
ShowDetailInfo2D();
System.out.println("좌표(z축): "+z);
}
}
class Box extends Rectangle{
protected int z, depth;
public Box() {
this("육면체",0,0,0,1,1,1);
}
public Box(String name, int x, int y, int z, int width, int height, int depth) {
super(name, x, y, width, height);
this.z = z;
this.depth = depth;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public int getDepth() {
return depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
public void ShowDetailInfo3D() {
ShowDetailInfo2D();
System.out.println("좌표(z축): "+z);
System.out.println("깊이: "+depth);
}
}
public class ShapeTest {
public static void main(String[] args) {
Shape sh_obj = new Shape();
sh_obj.ShowInfo();
Circle c_obj2 = new Circle("동전",5,3,4);
c_obj2.ShowDetailInfo2D();
Rectangle r_obj = new Rectangle("타일",7,5,11,13);
r_obj.ShowDetailInfo2D();
Sphere s_obj = new Sphere("공",9,9,5,8);
s_obj.ShowDetailInfo3D();
Box b_obj1 = new Box();
b_obj1.ShowDetailInfo3D();
Box b_obj2 = new Box("책",1,3,7,7,13,11);
b_obj2.ShowDetailInfo3D();
}
}