-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb001_String.java
More file actions
38 lines (26 loc) · 1019 Bytes
/
Copy pathProb001_String.java
File metadata and controls
38 lines (26 loc) · 1019 Bytes
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
package java0905_api.answ;
/*
* [출력결과]
* Samsung 상품 정보
* 제품번호 : PROD-00001, 제품명 : 갤럭시S, 수량 : 5, 가격 : 940000
*/
public class Prob001_String {
public static void main(String[] args) {
String msg = "PROD-00001**Samsung**갤럭시S**5**940000";
Product prod = createProduct(msg);
System.out.println(prod.getMaker() + " 상품 정보");
System.out.println(prod.toString());
}//end main()
private static Product createProduct(String message) {
//매개변수로 들어온 문자열을 적절히 이용하여
//Product 객체를 생성후 리턴하는createProduct() 메서드를 구현하시오.
String[] data=message.split("\\*{2}");
Product pt=new Product();
pt.setProductId(data[0]);
pt.setMaker(data[1]);
pt.setName(data[2]);
pt.setAmount(Integer.parseInt(data[3]));
pt.setPrice(Integer.parseInt(data[4]));
return pt;
}// end creatProduct
}// end class