-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBill.swift
90 lines (68 loc) · 1.79 KB
/
Bill.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// Bill.swift
// PreWork
//
// Created by My Mac on 1/29/21.
//
import Foundation
//Bill class
class Bill {
private var tipPercent : Double = 0.0;
private var amt : Int = 0;
private var bills : [Double] = [0.0,0.0]
private var value : String = ""
private var person : Int = 0
//initializers
//default
init() {
}
//paramterized
init(tipPercent : Double) {
self.tipPercent = tipPercent
}
//calculation of the tip and bill
func calculate() -> [Double]{
let value = updateAmount()
let dValue = Double(value) ?? 0.00
let tip = dValue * tipPercent
var splitBill = 0.0
//divides by the number of people
if(person >= 0){
splitBill = (dValue + tip)/Double(person+1)
}
//let totalBill = (dValue + tip)
bills[0] = tip
//bills[1] = totalBill
bills[1] = splitBill
return bills
}
//calculates the
private func updateAmount() -> String{
print("inAmount",amt)
let amount = Double(amt/100) + Double(amt%100)/100
value = String(amount)
return String(amount)
}
// setters and getters
func setPersonsAndCalc(person : Int) -> [Double]{
self.person = person
return calculate()
}
func updateAmt(amt : Int) -> String{
self.amt = amt
return updateAmount()
}
func setDatas(amt : Int, tipPercent : Double){
self.tipPercent = tipPercent
self.amt = amt
}
func getAmt() -> Int{
return amt
}
func getValue() -> String{
return value
}
func getBills () -> [Double]{
return bills
}
} //end of Bill class