[1008] UML대로 구현하기
2019. 10. 8. 18:08
객체지향설계 시간에 UML을 배우고 나서 draw.io 프로그램을 이용해서 직접 관계를 따져 그려보고 이것을 참고해서 아래와 같은 python 코드로 구현하였다. 위의 UML을 그릴 때 표현된 선은 아래와 같은 클래스들의 관계에 따라 선의 종류를 바꿔서 표현하였다.
위의 UML대로 구현한 Python 코드는 아래와 같다.
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
class Customer:
def __init__(self, name, address):
self.name = name
self.address = address
print("Your address : ",self.address)
print ("new Customer's Order")
class OrderDetail:
def __init__(self, quantity, taxStatus):
self.quantity = quantity
self.taxStatus = taxStatus
def calcSubTotal(self):
total = self.quantity * 1000
print("")
print("SubTotal Prize is ...", total, 'won')
def calcWeight(self):
total = self.quantity * 500
print("Weight is...", total, 'g')
def clacTax(self):
total = self.quantity * self.taxStatus
print("Total taxStatus is...", total, 'won')
class Order:
def __init__(self, date, status):
self.date = date
self.status = status
check = input("show Order Detail?(Y/N) : ")
if(check == 'Y'):
odetail = OrderDetail(10, 50)
odetail.calcSubTotal()
odetail.calcWeight()
odetail.clacTax()
elif(check == 'N'):
print("")
print("LOGOUT...")
class Check:
def __init__(self, name, bankID):
self.name = name
self.bankID = bankID
def authorized(self):
print("")
print("ORDER COMPLETE!")
order = Order("2019-10-08", "Order Complete")
else:
print("")
print("ORDER FAIL... TRY AGAIN NEXT TIME")
class Credit:
def __init__(self, number, type, expDate):
self.number = number
self.type = type
self.expDate = expDate
def authorized(self):
print("")
print("correct Infomation go to Check Page ...")
print("")
name = input("your Name? : ")
bankID = int(input("insert Your ID : "))
check = Check(name, bankID)
check.authorized()
else:
print("incorrect Information!")
class Cash:
def __init__(self, cashTendered):
self.cashTendered = cashTendered
print("")
print("you cash is ", self.cashTendered, "won.")
print("ORDER COMPLETE!")
order = Order("2019-10-08", "Order Complete")
class Payment:
def __init__(self, amount):
self.amount = amount
print(self.amount)
number = int(input("get your number : "))
type = input("card type : ")
expDate = int(input("car expDate : "))
credit = Credit(number, type, expDate)
credit.authorized()
cash = int(input("your prize is 10000won.(write down prize won...) : "))
cash = Cash(cash)
else:
print("Choose again")
x = int(input("your Choose : "))
p = Payment(x)
class Item:
def __init__(self, shippingWeight, description):
self.shippingWeight = shippingWeight #원하는 수량
self.description = description #재고 수량
def getPriceForQuantity(self): #총가격
price = 1000 * self.shippingWeight
print("That Total price is ", price, 'won')
def getTax(self): #총세금
tax = 50 * self.shippingWeight
print("Tax Total price is ", tax, 'won')
def inStock(self): #재고수량
stock = self.description
print("Goods Stock... ", stock)
#Main
name = input("WELCOME, Customers. Your Name is? : ")
add = input("Your Address is? :")
cus = Customer(name, add)
print("")
print("What do you want to BUY? Please Check Goods List...")
print("1. Milk 2. Orange Juice 3. Mouse 4. KeyBoard 5. Ice Cream")
choose = int(input("choose ONE : "))
if choose == 1:
thisis = "Milk"
thisQ = 10
elif choose == 2:
thisis = "Orange Juice"
thisQ = 20
elif choose == 3:
thisis = "Mouse"
thisQ = 30
elif choose == 4:
thisis = "KeyBoard"
thisQ = 40
elif choose == 5:
thisis = "Ice cream"
thisQ = 50
print("you Choose", thisis , ", How much Quantity you want? : ")
quan = int(input("Quantity : "))
item = Item(quan, thisQ)
item.getPriceForQuantity()
item.inStock()
print("")
ans = input("Do you want to buy this?(Y/N) : ")
if(ans == 'Y'):
print("")
print("Please Choose Payment method")
print("1. Credit")
print("2. Cash")
x = int(input("you Answer? : ")) #값 입력받기
payment = Payment(x)
elif(ans == 'N'):
print("See YOU Next Time!")
|
원래는 추상적인 클래스들의 정보만 제공이 되고 구체적인 동작은 제시해주지 않았기 때문에 UML을 구현한대로 내가 만들고 싶은 동작대로 구현을 해 보았다. Python에 조금이나마 익숙해진 것 같아 좋은 경험이 되었다.
아래에 첨부된 사진은 위의 코드를 동작시켰을 때 UML대로 관계를 가지고 순차적으로 실행되는 것을 볼 수 있다.
'Undergraduate Records' 카테고리의 다른 글
잊어버리기 전에 쓰는 gitHub 간단 Push 방법 (0) | 2019.10.12 |
---|---|
[1011] 코드아카데미 php 실습 과제 (0) | 2019.10.11 |
[1007] CountingSort(계수정렬), HeapSort(힙정렬) (1) | 2019.10.07 |
[1004] replaceByte 문제 해결 (0) | 2019.10.05 |
[1001] DataLab 문제 해결 보고서 (0) | 2019.10.02 |