-
Notifications
You must be signed in to change notification settings - Fork 166
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
Week3 [Step2] som #100
Week3 [Step2] som #100
Changes from 20 commits
b748fb5
c6f044c
dd712c4
2f8c428
b2cbee9
bd2b430
1f3eace
1a6997e
6345bab
b5d94ce
006504a
e0b746d
9a612bf
e5505f3
61fa0c0
a5b5d4d
7b7ab87
23b20b7
edb8a9b
265660a
2750a4a
d63d69a
63332ec
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 |
---|---|---|
|
@@ -7,22 +7,60 @@ | |
|
||
import Foundation | ||
|
||
struct CoffeeShop { | ||
var owner: String | ||
var openingHours: String | ||
var coffeeShopProfit: Int? | ||
class CoffeeShop { | ||
let owner: String | ||
let openingHours: String | ||
var coffeeShopProfit: Int = 0 | ||
var menu: [Coffee: Int] | ||
var pickUpTable: Coffee? = nil | ||
var pickUpTable: Coffee? { | ||
didSet { | ||
if let coffee = pickUpTable { | ||
print("\(customerName)님, \(coffee)가 완성되어 픽업 테이블에 올라왔습니다.") | ||
} | ||
} | ||
} | ||
var barista: Person? | ||
init(owner: String, openingHours: String, coffeeShopProfit: Int? = nil, menu: [Coffee: Int] = [:], barista: Person? = nil) { | ||
var customerName: String = "" | ||
|
||
init(owner: String, openingHours: String, menu: [Coffee: Int] = [:], barista: Person?) { | ||
self.owner = owner | ||
self.openingHours = openingHours | ||
self.coffeeShopProfit = coffeeShopProfit | ||
self.menu = menu | ||
self.barista = barista | ||
} | ||
func makeCoffee(_ coffee: Coffee) { | ||
print("\(coffee)를 만드는 중입니다.") | ||
|
||
func openStateOfCafe() { | ||
if openingHours.isEmpty { | ||
print("[CLOSE]") | ||
} else { | ||
print("[OPEN]") | ||
} | ||
} | ||
|
||
func showMenu() { | ||
if menu.isEmpty { | ||
print("현재 메뉴 준비 중입니다.") | ||
} else { | ||
print("☕️☕️☕️ \(owner) 카페 메뉴판 ☕️☕️☕️") | ||
for (coffee, price) in menu { | ||
print("|| \(coffee) - \(price)원 ||") | ||
} | ||
print("----------------------------") | ||
} | ||
|
||
} | ||
|
||
func order(_ coffee: Coffee, price: Int, customerName: String) { | ||
openCafe() | ||
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.
|
||
showMenu() | ||
print("\(customerName) 님의 \(coffee) 주문이 들어왔습니다.") | ||
self.customerName = customerName | ||
coffeeShopProfit += price | ||
makeCoffee(menu: coffee) | ||
} | ||
|
||
func makeCoffee(menu coffee: Coffee) { | ||
pickUpTable = 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. 제가 지난 코멘트에서 알려드린 다음 커밋에 포함시켜보세요!! 😄 |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,21 +7,44 @@ | |
|
||
import Foundation | ||
|
||
struct Person { | ||
var name: String | ||
var age: Int | ||
class Person { | ||
let name: String | ||
let age: Int | ||
var habit: String? | ||
var personalMBTI: String? | ||
var MBTI: String? | ||
var walletInCash: Int | ||
init(name: String, age: Int, habit: String? = nil, personalMBTI: String? = nil, walletInCash: Int) { | ||
|
||
init(name: String, age: Int, habit: String? = nil, MBTI: String? = nil, walletInCash: Int) { | ||
self.name = name | ||
self.age = age | ||
self.habit = habit | ||
self.personalMBTI = personalMBTI | ||
self.MBTI = MBTI | ||
self.walletInCash = walletInCash | ||
} | ||
func buyCoffee(_ coffee: Coffee) { | ||
print("\(name)이 \(coffee)를 삽니다.") | ||
print("\(name)에게 \(walletInCash)원이 남았어요") | ||
|
||
func spandCash(amount: Int) { | ||
if isPayable(amount) == false { | ||
print("잔돈이 부족합니다.") | ||
} else { | ||
walletInCash -= amount | ||
} | ||
} | ||
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. 이 메서드는 구현은 됐지만, 호출되고 있지 않습니다. 따라서, 삭제 커밋 해주시면 좋겠습니다! 😄 |
||
|
||
func isPayable(_ amount: Int) -> Bool { | ||
return walletInCash >= amount | ||
} | ||
|
||
func buyCoffee(_ coffee: Coffee, at coffeeShop: CoffeeShop) { | ||
guard let price = coffeeShop.menu[coffee] else { | ||
print("주문한 커피가 메뉴에 없습니다.") | ||
return | ||
} | ||
if isPayable(price) { | ||
walletInCash -= price | ||
coffeeShop.order(coffee, price: price, customerName: name) | ||
} else { | ||
print("\(coffee) 를 주문하기엔 잔액이 \(price - walletInCash)원 부족합니다.") | ||
} | ||
} | ||
} | ||
|
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.
프로퍼티 옵저버 정말 잘 만드셨어요! 💯