-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Round3] Step1 - hansol #342
base: ss_19_hansol
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Foundation | ||
|
||
enum Coffee: String { | ||
case americano = "아메리카노" | ||
case cafeLatte = "카페라떼" | ||
case cappuccino = "카푸치노" | ||
|
||
var orderMenu: String { | ||
return self.rawValue | ||
} | ||
} | ||
|
||
class Person { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Person타입은 왜 클래스로 선언하였는지 궁금합니다! |
||
var name: String = "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. init을 활용하지 않고 기본값을 준 이유가 궁금해요! |
||
var money: Int = 0 | ||
|
||
func order(_ coffee: Coffee, of coffeeShop: CoffeeShop, by name: String) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인자 레이블과 파라미터의 활용 너무 좋습니다! 👍 |
||
if let price = coffeeShop.menu[coffee] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if문 다음의 로직 흐름으로 이어질 필요가 없다면 guard-let을 활용하는게 좋답니다 :) |
||
if money >= price { | ||
money -= price | ||
print("\(name)님이 \(price)원에 \(coffee.orderMenu)를 결제했습니다.") | ||
coffeeShop.make(coffee, from: name) | ||
} else { | ||
print("\(name)님의 잔액이 부족하여 \(coffee.orderMenu)를 구매하실 수 없습니다.") | ||
print("잔액이 \(price - money)원만큼 부족합니다.") | ||
} | ||
} else { | ||
print("\(coffee.orderMenu)는 카페에서 판매하지 않습니다.") | ||
} | ||
} | ||
} | ||
|
||
class CoffeeShop { | ||
var shopName: String = "" | ||
var menu: [Coffee: Int] = [:] | ||
var revenue: Int = 0 | ||
var pickUpTable: [Coffee] = [] | ||
var barista: Person? | ||
|
||
func assignBarista(barista: Person) { | ||
self.barista = barista | ||
print("\(shopName)을 담당하는 바리스타는 \(barista.name)입니다.") | ||
} | ||
|
||
func make(_ coffee: Coffee, from name: String) { | ||
if let price = menu[coffee] { | ||
revenue += price | ||
pickUpTable.append(coffee) | ||
print("바리스타 \(barista?.name ?? "바리스타")가 \(coffee.orderMenu)를 만들어 픽업 테이블에 올려놨습니다.") | ||
print("\(name)님이 주문하신 \(coffee.orderMenu)(이/가) 준비되었습니다. 픽업대에서 가져가주세요.") | ||
} else { | ||
print("\(coffee.orderMenu)는 메뉴에 없습니다.") | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orderMenu라는 네이밍이 변수보다 함수와 가까운 네이밍인 것 같아요!
간단하게 name 정도로 해줘도 좋을 것 같습니다 :)
외부에서 사용할때 Coffee.name으로 하니깐요 😀