-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTipCalculatorModel.swift
48 lines (38 loc) · 967 Bytes
/
TipCalculatorModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// TipCalculatorModel.swift
// TipCalculator
//
// Created by John Readey on 8/12/14.
// Copyright (c) 2014 Wonderland. All rights reserved.
//
import Foundation
// 1
class TipCalculatorModel {
// 2
var total: Double
var taxPct: Double
var subtotal: Double {
get {
return total / (taxPct + 1)
}
}
// 3
init(total:Double, taxPct:Double) {
self.total = total
self.taxPct = taxPct
}
// 4
func calcTipWithTipPct(tipPct:Double) -> Double {
var foo = Dictionary<Int, Double>()
return subtotal * tipPct
}
func returnPossibleTips() -> Dictionary<Int, Double> {
let possibleTipsInferred = [0.15, 0.18, 0.20]
var retval = Dictionary<Int, Double>()
for possibleTip in possibleTipsInferred {
let intPct = Int(possibleTip*100)
retval[intPct] = calcTipWithTipPct(possibleTip)
}
return retval
}
}