Skip to content
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

Open
wants to merge 2 commits into
base: ss_19_hansol
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions CodeStarterCamp_Week3/CoffeeShop.swift
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 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orderMenu라는 네이밍이 변수보다 함수와 가까운 네이밍인 것 같아요!
간단하게 name 정도로 해줘도 좋을 것 같습니다 :)
외부에서 사용할때 Coffee.name으로 하니깐요 😀

return self.rawValue
}
}

class Person {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Person타입은 왜 클래스로 선언하였는지 궁금합니다!

var name: String = ""
Copy link

Choose a reason for hiding this comment

The 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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인자 레이블과 파라미터의 활용 너무 좋습니다! 👍

if let price = coffeeShop.menu[coffee] {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if문 다음의 로직 흐름으로 이어질 필요가 없다면 guard-let을 활용하는게 좋답니다 :)
저는 개인적으로 guard문을 통과하지 못할때 빠르게 함수가 종료된다는 것과 가독성때문에
guard문을 조금 더 애용하고 있어요!

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)는 메뉴에 없습니다.")
}
}
}
24 changes: 23 additions & 1 deletion CodeStarterCamp_Week3/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,27 @@

import Foundation

print("Hello, World!")
let misterLee = Person()
misterLee.name = "misterLee"
misterLee.money = 3000

let missKim = Person()
missKim.name = "missKim"
missKim.money = 20000

let menu: [Coffee: Int] = [
.americano: 5000,
.cafeLatte: 6000,
.cappuccino: 7000
]

let yagombucks = CoffeeShop()
yagombucks.shopName = "yagombucks"
yagombucks.menu = menu

yagombucks.assignBarista(barista: misterLee)
missKim.order(.cafeLatte, of: yagombucks, by: missKim.name)
misterLee.order(.americano, of: yagombucks, by: misterLee.name)

print("\(yagombucks.shopName)의 매출액: \(yagombucks.revenue)원")
print("픽업 테이블에 있는 커피: \(yagombucks.pickUpTable.map { $0.orderMenu }.joined(separator: ", "))")