-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb04_class.java
More file actions
54 lines (44 loc) · 1.24 KB
/
Copy pathProb04_class.java
File metadata and controls
54 lines (44 loc) · 1.24 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
package java0829_class.answ;
/* 1 display()메소드에서 code별 가격합계를 구현하는 프로그램을 구현하시오.
*
* 2 출력결과
* 컴퓨터 75000
* 소설 25000
*
*/
class BookShop {
//멤버변수
String title;
String code;
int price;
BookShop(String title, String code, int price) {
this.title = title;
this.code = code;
this.price = price;
}
}
public class Prob04_class {
public static void main(String[] args) {
BookShop[] shop=new BookShop[5];
shop[0]=new BookShop("Java의 정석","컴퓨터",20000);
shop[1]=new BookShop("나그네","소설",10000);
shop[2]=new BookShop("실무에 바로쓰는 엑셀","컴퓨터",25000);
shop[3]=new BookShop("초인","소설",15000);
shop[4]=new BookShop("웹구현 JSP","컴퓨터",30000);
display(shop);
}//end main()
public static void display(BookShop[] shop){
//code별 가격 합계를 구하는 프로그램을 구현하시오.
int sumx = 0;
int sumy = 0;
for(int i=0;i<shop.length;i++){
if (shop[0].code==shop[i].code){
sumx+=shop[i].price;
}else{
sumy+=shop[i].price;
}
}
System.out.println("컴퓨터"+sumx);
System.out.println("소설 "+sumy);
}//end display()
}//end class