-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExchangeRate class
52 lines (39 loc) · 1.74 KB
/
ExchangeRate class
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
class ExchangeRate {
let fromCurrency: String
let toCurrency: String
let baseAmount: UInt
var rate: Float
init(from: String, to: String, base: UInt, rate: Float) {
fromCurrency = from
toCurrency = to
baseAmount = base
self.rate = rate
}
var description : String {
return ("\(baseAmount) \(fromCurrency) = \(rate) \(toCurrency)")
}
}
var exchangeRateTable: [ExchangeRate] = []
var chfToEuro: ExchangeRate = ExchangeRate(from: "CHF", to: "EURO", base: 1, rate: 1.15)
var chfToUsd: ExchangeRate = ExchangeRate(from: "CHF", to: "USD", base: 1, rate: 0.98)
var chfToGbp: ExchangeRate = ExchangeRate(from: "CHF", to: "GBP", base: 1, rate: 1.35)
var euroToJpy: ExchangeRate = ExchangeRate(from: "EURO", to: "JPY", base: 1, rate: 1045)
var euroToGbp: ExchangeRate = ExchangeRate(from: "EURO", to: "GBP", base: 1, rate: 1.25)
var jpyToEuro: ExchangeRate = ExchangeRate(from: "JPY", to: "EURO", base: 1000, rate: 1.11)
var exchangeRateTable2: [ExchangeRate] = []
var usdToChf: ExchangeRate = ExchangeRate(from: "USD", to: "CHF", base: 1, rate: 0.99)
var gbpToChf: ExchangeRate = ExchangeRate(from: "GBP", to: "CHF", base: 1, rate: 1.23)
var chfToJpy: ExchangeRate = ExchangeRate(from: "CHF", to: "JPY", base: 1, rate: 108.61)
exchangeRateTable.append(ExchangeRate(from: "CHF", to: "EURO", base: 1, rate: 1.15))
exchangeRateTable.append(chfToEuro)
exchangeRateTable.append(chfToUsd)
exchangeRateTable.append(chfToGbp)
exchangeRateTable.append(euroToJpy)
exchangeRateTable.append(euroToGbp)
exchangeRateTable.append(jpyToEuro)
exchangeRateTable.append(usdToChf)
exchangeRateTable.append(gbpToChf)
exchangeRateTable.append(chfToJpy)
for line in exchangeRateTable {
print(line.description)
}