-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava077_class.java
More file actions
68 lines (57 loc) · 1.71 KB
/
Copy pathJava077_class.java
File metadata and controls
68 lines (57 loc) · 1.71 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
package java0829_class;
/*
* [데이터]
* a001 생명보험 자동차보험 30000
* a002 생명보험 운전자보험 20000
* b001 손해보험 화재보험 15000
* b002 손해보험 해상보험 25000
*
* [출력결과]
* 손해보험 총납입액은 40000원 입니다.
*/
class Insurance {
String code; // 상품코드
String name; // 상품명
String type; // 상품종류
int payment; // 납입보험료
public Insurance() {
}
public Insurance(String code, String name, String type, int payment) {
this.code = code;
this.name = name;
this.type = type;
this.payment = payment;
}
public void prn() {
System.out.printf("%s %s %s %d\n", code, name, type, payment);
}
}// end Insurance
public class Java077_class {
public static void main(String[] args) {
String search = "손해보험";
Insurance[] is = new Insurance[4];
is[0] = new Insurance("a001", "생명보험", "자동차보험", 30000);
is[1] = new Insurance("a002", "생명보험", "운전자보험", 20000);
is[2] = new Insurance("b001", "손해보험", "화재보험", 15000);
is[3] = new Insurance("b002", "손해보험", "해상보험", 25000);
int sum = process(is, search);
totalPrice(sum, search);
}// end main( )
public static int process(Insurance[] is, String name) {
// 여기를 구현하세요////////////////
int sum = 0;
/*for (int i = 0; i < is.length; i++) {
if (is[i].name == name) {
sum += is[i].payment;
}
}*/
for (Insurance ie : is) {
if (ie.name == name)
sum += ie.payment;
}
return sum;
}// end process( )
public static void totalPrice(int sum, String name) {
System.out.printf("%s 총납입액은 %d원 입니다.\n", name, sum);
}
}// end class