티스토리 뷰
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
package oop;
import java.util.Scanner;
/**
@author pakjkwan@gmail.com
@since 2020.06.18
@param kind 폰종류 , company 제조사, call 통화내역
*/
class Product{
}
class TV extends Product{
public final static String KIND = "텔레비전";
@Override public String toString() {return String.format("%s", KIND);}
}
class ColorTV extends TV{
public final static String KIND = "컬러 텔레비전";
@Override public String toString() {return String.format("%s", KIND);}
}
class Computer extends Product{
public final static String KIND = "컴퓨터";
@Override public String toString() {return String.format("%s", KIND);}
}
class Notebook extends Computer{
public final static String KIND = "노트북";
@Override public String toString() {return String.format("%s", KIND);}
}
class ZipPhone extends Product{
protected String kind, company, call;
public String getKind() {return kind;}
public void setKind(String kind) {this.kind = kind;}
public String getCompany() {return company;}
public void setCompany(String company) {this.company = company;}
public String getCall() {return call;}
public void setCall(String call) {this.call = call;}
@Override
public String toString() {
return "집전화기 [폰종류=" + kind + ", 제조사=" + company + ", 통화내역=" + call + "]";
}
}
class MobilePhone extends ZipPhone{
public final static String KIND = "휴대폰";
protected boolean portable;
protected String move;
public boolean isPortable() {return portable;}
public void setPortable(boolean portable) {
move = (portable) ? "이동중에" : "이동불가능";
this.portable = portable;
}
public String getMove() {return move;}
public void setMove(String move) {this.move = move;}
@Override
public String toString() {
return String.format("%s 인 %s 제품을 사용해서 %s 라고 %s 통화한다",
KIND, company, call, move);
}
}
class ApplePhone extends MobilePhone{
public final static String KIND = "아이폰";
protected String search;
public String getSearch() {return search;}
public void setSearch(String search) {this.search = search;}
@Override
public String toString(){return String.format("%s", KIND);}
}
class SamsungPhone extends ApplePhone{
protected String pay;
public final static String KIND = "갤럭시";
public String getPay() {return pay;}
public void setPay(String pay) {this.pay = pay;}
@Override
public String toString() {return String.format("%s", KIND);}
}
public class CartApp{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Product item = null;
Product[] cart = new Product[5];
int index = 0;
while(true) {
System.out.println("쇼핑목록: 0.종료 1.아이폰 2.갤럭시 3. 컬러TV"
+ "4. 컴퓨터 5. 노트북 6. 쇼핑목록보기");
switch (scanner.nextInt()) {
case 0:return;
case 1:cart[index] = new ApplePhone(); index++; break;
case 2:cart[index] = new SamsungPhone(); index++; break;
case 3:cart[index] = new ColorTV(); index++; break;
case 4:cart[index] = new Computer(); index++; break;
case 5:cart[index] = new Notebook(); index++; break;
case 6:
System.out.println("구매목록");
for(Product p : cart) {
System.out.println(p.toString());
}
default:
break;
}
}
}
}
|
cs |
'1. 자바' 카테고리의 다른 글
CRUD - Member.java (0) | 2020.08.14 |
---|---|
행렬(Matrix) - Lotto.java (0) | 2020.08.14 |
스프링/--/하이파/ 타이타닉 PassengerRepository.java (0) | 2020.08.07 |
[Madrid] Intellij Format Yaml Plugins 설정하기 (0) | 2020.08.02 |
자바/인텔리제이/2020-07-31/ 설정과 단축키 (0) | 2020.07.31 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- mariadb
- intellij
- JPA
- React
- database
- COLAB
- Mongo
- ERD
- jQuery
- Python
- Eclipse
- Django
- SpringBoot
- KAFKA
- AWS
- JUnit
- vscode
- docker
- Oracle
- maven
- Java
- SQLAlchemy
- nodejs
- Mlearn
- terms
- Git
- Algorithm
- tensorflow
- springMVC
- FLASK
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함