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

Week3 [Step2] som #100

Merged
merged 23 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b748fb5
구조체 타입에서 클래스 타입으로 변경
May 4, 2022
c6f044c
CoffeeShop 소스 파일 - showMenu() 메서드 추가
May 4, 2022
dd712c4
CoffeeShop 소스 파일 - showMenu() 메서드 위치 수정
May 4, 2022
2f8c428
CoffeeShop 소스 파일 - order() 메서드 수정
May 4, 2022
b2cbee9
Person 소스 파일 - spandCash() 메서드 추가
May 4, 2022
bd2b430
Person 소스 파일 - isPayable() 메서드 추가
May 4, 2022
1f3eace
CoffeeShop 소스 파일 - order() 메서드 수정
May 4, 2022
1a6997e
Person 소스 파일 - buyCoffee() 메서드 수정
May 4, 2022
6345bab
돈이 부족할 경우, 잔액 메세지 수정
May 4, 2022
b5d94ce
픽업테이블 메세지 호출 추가
May 4, 2022
006504a
Person MBTI 프로퍼티 이름 변경
May 4, 2022
e0b746d
Person 소스 파일 - isPayable() 메서드 수정
May 6, 2022
9a612bf
Person 소스 파일 - Person class 공백 수정
May 6, 2022
e5505f3
Person 소스 파일 - buyCoffee() 메서드 수정
May 6, 2022
61fa0c0
CoffeeShop 소스 파일 - showMenu() 메서드 수정
May 7, 2022
a5b5d4d
CoffeeShop 소스 파일 - order() 메서드 수정
May 7, 2022
7b7ab87
CoffeeShop 소스 파일 - makeCoffee() 메서드 수정
May 7, 2022
23b20b7
Person 소스 파일 - buyCoffee() 메서드 수정
May 7, 2022
edb8a9b
main 소스 파일 수정
May 7, 2022
265660a
CoffeeShop 소스 파일 - openStateOfCafe() 메서드 추가
May 7, 2022
2750a4a
CoffeeShop 소스 파일 - openStateOfCafe() 메서드 호출문 수정
May 7, 2022
d63d69a
Person 소스 파일 - isSpend() 메서드 삭제
May 7, 2022
63332ec
CoffeeShop 소스 파일 - makeCoffee() 메서드 수정
May 7, 2022
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
56 changes: 47 additions & 9 deletions CodeStarterCamp_Week3/CoffeeShop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)가 완성되어 픽업 테이블에 올라왔습니다.")
}
}
}
Comment on lines +15 to +21
Copy link
Member

Choose a reason for hiding this comment

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

프로퍼티 옵저버 정말 잘 만드셨어요! 💯

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()
Copy link
Member

Choose a reason for hiding this comment

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

openCafe() 라는 메서드가 존재하지 않아서, 컴파일이 안 됩니다. 😢
커밋 찍기 전에 꼭 컴파일 성공 여부를 확인해주세요! 👍🏻

showMenu()
print("\(customerName) 님의 \(coffee) 주문이 들어왔습니다.")
self.customerName = customerName
coffeeShopProfit += price
makeCoffee(menu: coffee)
}

func makeCoffee(menu coffee: Coffee) {
pickUpTable = coffee
}
Copy link
Member

Choose a reason for hiding this comment

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

제가 지난 코멘트에서 알려드린 Thread.sleep 사용해서, 커피가 만들어지는 데 시간을 부여해보셔도 좋아요!
위험한 메서드이지만, 사용해보라고 알려드렸던 거에요. 👍🏻

다음 커밋에 포함시켜보세요!! 😄

}

Expand Down
41 changes: 32 additions & 9 deletions CodeStarterCamp_Week3/Person.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이 메서드는 구현은 됐지만, 호출되고 있지 않습니다.
그리고 삭제하더라도, 프로그램 실행에 전혀 문제가 없네요!

따라서, 삭제 커밋 해주시면 좋겠습니다! 😄
그리고 오타도 있네요. ㅎㅎㅎ spand → spend


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)원 부족합니다.")
}
}
}

8 changes: 5 additions & 3 deletions CodeStarterCamp_Week3/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import Foundation

//Person 타입의 인스턴스로 misterLee , missKim 을 생성
let missKim = Person(name: "missKim", age: 35, walletInCash: 10000)
let misterLee = Person(name: "misterLee", age: 31, habit: "농구", personalMBTI: "INFJ", walletInCash: 20000)
let misterLee = Person(name: "misterLee", age: 31, habit: "농구", MBTI: "INFJ", walletInCash: 20000)

//CoffeeShop 타입의 인스턴스로 yagombucks 을 생성
var yagombucks = CoffeeShop(owner: "야곰", openingHours: "10:00 ~ 20:00", menu: Coffee.menu, barista: misterLee)

let yagombucks = CoffeeShop(owner: "야곰", openingHours: "10:00 ~ 20:00", menu: Coffee.menu, barista: misterLee)

missKim.buyCoffee(.caramelMacchiato, at: yagombucks)
missKim.buyCoffee(.americano, at: yagombucks)
missKim.buyCoffee(.caffeLatte, at: yagombucks)