-
Notifications
You must be signed in to change notification settings - Fork 133
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
Step 2 : 우선순위와 다중처리 (리나) #15
Changes from 14 commits
cddcec2
a2e1d67
0808ffb
1e5e812
1469445
f7a8960
731cdc8
e29cbf7
f352b0f
ec2f607
6b6ebdb
c156f4a
92cf265
cd1a429
e4867b5
212b411
6560e84
98ed667
610a87c
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,13 +7,13 @@ | |
|
||
import Foundation | ||
|
||
class Dashboard { | ||
struct Dashboard { | ||
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. 구조체로 바꾼 이유는 무엇인가요? |
||
static func printMenu() { | ||
print(Menu.description, terminator: " ") | ||
} | ||
|
||
static func printStatus(for client: Client, about message: Message) { | ||
let message = String(format: message.rawValue, client.waitingNumber) | ||
static func printStatus(for client: Client, about message: String) { | ||
let message = String(format: message, client.waitingNumber, client.priority.description, client.businessType.description) | ||
print(message) | ||
} | ||
|
||
|
@@ -22,7 +22,7 @@ class Dashboard { | |
print(BankError.unknown.description) | ||
return | ||
} | ||
let message = String(format: Message.close.rawValue, number, time) | ||
let message = String(format: Message.close, number, time) | ||
print(message) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,31 @@ enum Menu: String { | |
""" | ||
} | ||
|
||
enum Message: String { | ||
case close = "업무가 마감되었습니다. 오늘 업무를 처리한 고객은 총 %d명이며, 총 업무시간은 %.2f초입니다." | ||
case tellerStart = "%d번 고객 업무 시작" | ||
case tellerFinish = "%d번 고객 업무 완료" | ||
enum Message { | ||
static let close = "업무가 마감되었습니다. 오늘 업무를 처리한 고객은 총 %d명이며, 총 업무시간은 %.2f초입니다." | ||
static let tellerStart = "%d번 %@고객 %@업무 시작" | ||
static let tellerFinish = "%d번 %@고객 %@업무 완료" | ||
} | ||
Comment on lines
-21
to
25
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. case 을 static let 으로 바꾼 이유는 무엇인가요? |
||
|
||
enum BusinessType { | ||
case normal | ||
enum BusinessType: CaseIterable { | ||
case deposit | ||
case loan | ||
|
||
var neededTime: TimeInterval { | ||
switch self { | ||
case .normal: | ||
case .deposit: | ||
return 0.7 | ||
case .loan: | ||
return 1.1 | ||
} | ||
} | ||
|
||
var description: String { | ||
switch self { | ||
case .deposit: | ||
return "예금" | ||
case .loan: | ||
return "대출" | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,35 +6,13 @@ | |
|
||
import Foundation | ||
|
||
private func randomNumber(from minNumber: Int = 0, to maxNumber: Int) -> Int { | ||
return Int.random(in: minNumber...maxNumber) | ||
} | ||
|
||
private func initClients(_ number: Int) -> [Client]? { | ||
var clients: [Client] = [] | ||
|
||
for waitingNumber in 1...number { | ||
clients.append(Client(waitingNumber: waitingNumber)) | ||
} | ||
return clients | ||
} | ||
|
||
private func main() { | ||
lina0322 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let bank = Bank() | ||
let tellerNumber = 3 | ||
let maxClientNumber = 30 | ||
let minClientNumber = 10 | ||
var isContinue = true | ||
lina0322 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func initClients(_ number: Int) -> [Client] { | ||
var clients: [Client] = [] | ||
|
||
for waitingNumber in 1...number { | ||
clients.append(Client(waitingNumber: waitingNumber)) | ||
} | ||
return clients | ||
} | ||
|
||
while isContinue { | ||
Dashboard.printMenu() | ||
|
||
|
@@ -45,12 +23,31 @@ private func main() { | |
|
||
switch command { | ||
case .start: | ||
let clients = initClients(randomNumber(from: minClientNumber, to: maxClientNumber)) | ||
guard let clients = initClients(randomNumber(from: minClientNumber, to: maxClientNumber)) else { | ||
lina0322 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
} | ||
bank.operateBank(teller: tellerNumber, client: clients) | ||
case .end: | ||
isContinue = false | ||
} | ||
} | ||
} | ||
|
||
private func randomNumber(from minNumber: Int = 0, to maxNumber: Int) -> Int { | ||
lina0322 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Int.random(in: minNumber...maxNumber) | ||
} | ||
|
||
private func initClients(_ number: Int) -> [Client]? { | ||
var clients: [Client] = [] | ||
|
||
for waitingNumber in 1...number { | ||
guard let businessType = BusinessType.allCases.randomElement(), let priority = Client.Priority.allCases.randomElement() else { | ||
return nil | ||
} | ||
|
||
clients.append(Client(waitingNumber: waitingNumber, businessType: businessType, priority: priority)) | ||
} | ||
return clients | ||
} | ||
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. 메인에서 메소드를 저장하는 것보다 좋은 방법이 있을 것 같아요. |
||
|
||
main() |
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.
case 이름을 일반으로 하지 않은 이유가 있나요?