Study
2008. 5. 31. 15:34
도형 중심좌표와 높이 너비, 다중 클래스 (상속)
public class Shape{ private double x,y; public Shape(double x, double y){ setX(x); setY(y); } public double getX(){ return x; } public void setX(double x){ this.x = x; } public double getY(){ return y; } public void setY(double y){ this.y = y; } } public class Circle extends Shape{ private double radius; public Circle(){ super(0,0); } public Circle(double x, double y){ super(x,y); } public Circle(double radius){ this(0,0); this.setRadius(radius); } public void draw(){ System.out.println("이 다각형은 원입니다."); System.out.println("\t중심좌표 : ("+this.getX()+", "+this.getY()+")"); System.out.println("\t반지름 : "+this.getRadius()+"\n"); } public double getRadius(){ return radius; } public void setRadius(double radius){ this.radius = radius; } } public class Triangle extends Shape{ private double width; private double height; public Triangle(double x, double y){ super(x,y); } public Triangle(double x, double y, double width, double height){ super(x,y); this.setWidth(width); this.setHeight(height); } public void draw(){ System.out.println("이 다각형은 삼각형입니다."); System.out.println("\t중심좌표 : ("+this.getX()+", "+this.getY()+")"); System.out.println("\t가로 : "+this.getWidth()); System.out.println("\t세로 : "+this.getHeight()+"\n"); } public double getWidth(){ return width; } public void setWidth(double width){ this.width = width; } public double getHeight(){ return height; } public void setHeight(double height){ this.height = height; } } public class Rectangle extends Shape{ private double width; private double height; public Rectangle(double x, double y){ super(x,y); } public Rectangle(double x, double y, double width, double height){ super(x,y); this.setWidth(width); this.setHeight(height); } public void draw(){ System.out.println("이 다각형은 사각형입니다."); System.out.println("\t중심좌표 : ("+this.getX()+", "+this.getY()+")"); System.out.println("\t가로 : "+this.getWidth()); System.out.println("\t세로 : "+this.getHeight()+"\n"); } public double getWidth(){ return width; } public void setWidth(double width){ this.width = width; } public double getHeight(){ return height; } public void setHeight(double height){ this.height = height; } } public class Output{ public static void main(String args[]){ Circle c1 = new Circle(4.5, 7.9); c1.setRadius(3.5); c1.draw(); Rectangle r1 = new Rectangle(2.5, 7.9); r1.setWidth(4.3); r1.setHeight(5.9); r1.draw(); Rectangle r2 = new Rectangle(2.5, 7.9, 3.6, 6.1); r2.draw(); Triangle t1 = new Triangle(3.5, 6.9); t1.setWidth(5.7); t1.setHeight(4.6); t1.draw(); Triangle t2 = new Triangle(3.5, 6.9, 6.2, 9.1); t2.draw(); } }
공유하기
게시글 관리
솔직한 목소리
blog
profile
tag cloud
travel log
guest book
by
bslime
전체보기
(52)
목소리
(1)
영화
(0)
음악
(0)
Study
(34)
Security
(12)
Web
(2)
WLAN
(7)
Network
(1)
System
(1)
Wargame
(5)
Web
(0)
Reverse Engineering
(3)
Crypto
(2)
미로
Algorithm
잘했어요
폐인
초대장
CTF
티스토리
padocon
Maze
삽질
«
2025/01
»
일
월
화
수
목
금
토
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
darktoil.
인생여전龍군.
슝이.
MR-J@.
미움.
vvipbeom.
Copyright ⓒ 2010.
bslime
, Skin designed by
Creasmworks.
All rights reserved.
티스토리툴바