-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava067_class.java
More file actions
62 lines (49 loc) · 1.01 KB
/
Copy pathJava067_class.java
File metadata and controls
62 lines (49 loc) · 1.01 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
package java0828_class;
/*
* [사각형 도형]
* 가로 세로 넓이를 구한다 둘레를 구한다
* 5 3 15 16
* 7 4 28 22
*/
/*
* [객체 모델링과정]
* 객체의 특징 : 가로, 세로
* 객체의 기능 : 넓이를 구한다, 둘레를 구한다.
*/
/*[출력결과]
[가로5, 세로3의 사각형]
넓이: 15
둘레: 16
=========================
[가로7, 세로4의 사각형]
넓이: 28
둘레: 22
*/
class Rect {
int width;
int height;
int area() {
return width * height;
}
int grith() {
return width * 2 + height * 2;
}
void prn() {
System.out.printf("[가로%d, 세로%d의 사각형]\n", width, height);
System.out.println("넓이: " + area());
System.out.println("둘레: " + grith());
}
}
public class Java067_class {
public static void main(String[] args) {
Rect t1 = new Rect();
t1.width = 5;
t1.height = 3;
t1.prn();
System.out.println("=========================");
Rect t2 = new Rect();
t2.width = 7;
t2.height = 4;
t2.prn();
}
}