-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnum14.java
More file actions
70 lines (63 loc) · 1.41 KB
/
Copy pathnum14.java
File metadata and controls
70 lines (63 loc) · 1.41 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
interface Shape {
final double PI = 3.14;
void draw();
double getArea();
default public void redraw() {
System.out.print("--- 다시 그립니다.");
draw();
}
}
class Circle implements Shape {
private int radius;
public Circle(int radius) {
this.radius = radius;
}
@Override
public void draw() {
System.out.println("반지름이 "+radius+"인 원입니다.");
}
@Override
public double getArea() {
return PI*radius*radius;
}
}
class Oval implements Shape {
private int n1,n2;
public Oval(int n1, int n2) {
this.n1 = n1;
this.n2 = n2;
}
@Override
public void draw() {
System.out.println(n1 + "x" + n2 + "에 내접하는 타원입니다." );
}
@Override
public double getArea() {
return PI*n1*n2;
}
}
class Rect implements Shape{
private int n1,n2;
public Rect(int n1, int n2) {
this.n1 = n1;
this.n2 = n2;
}
@Override
public void draw() {
System.out.println(n1 + "x" + n2 + "크기의 사각형 입니다." );
}
@Override
public double getArea() {
return n1*n2;
}
}
public class num14 {
public static void main(String[] args) {
Shape [] list = new Shape[3];
list[0] = new Circle(10);
list[1] = new Oval(20, 30);
list[2] = new Rect(10, 40);
for(int i=0; i<list.length; i++) list[i].redraw();
for(int i=0; i<list.length; i++) System.out.println("면적은 " + list[i].getArea());
}
}