-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcarModel.swift
205 lines (163 loc) · 3.67 KB
/
carModel.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// carModel.swift
// Copyright © 2016 Analystik. All rights reserved.
import Foundation
extension Array where Element: HasTitle {
func ToDictionary() -> Dictionary<Int, String> {
var d = Dictionary<Int,String>()
for ele in self {
d[ele.id] = ele.title()
}
return d
}
}
protocol HasTitle{
var id: Int! {get}
func title() -> String
}
class Make: HasTitle{
var id: Int!
var name: String!
init(){
self.id = 0;
self.name = ""
}
init(json: AnyObject){
if let id = json["Id"] as? Int{
self.id = id
}
if let name = json["Name"] as? String{
self.name = name
}
}
func title() -> String{
return self.name
}
}
class Model: HasTitle{
var id: Int!
var name: String!
var make: Make
init(){
self.id = 0;
self.name = ""
self.make = Make()
}
init(json: AnyObject){
if let id = json["Id"] as? Int{
self.id = id
}
if let name = json["Name"] as? String{
self.name = name
}
self.make = Make()
}
func title() -> String{
return self.name
}
}
class Car: HasTitle{
var id: Int!
var model:Model
var year4Digits: Int!
var consumption: Double!
var price: Int!
init(){
self.id = 0;
self.model = Model()
self.year4Digits = 0
self.consumption = 0.00
self.price = 0
}
init(json: AnyObject){
if let id = json["Id"] as? Int{
self.id = id
}
if let name = json["Year4Digits"] as? Int{
self.year4Digits = name
}
if let consumption = json["Consumption"] as? Double{
self.consumption = consumption
}
if let price = json["Price"] as? Int{
self.price = price }
self.model = Model()
}
func title() -> String{
return String(self.year4Digits)
}
}
class Province: HasTitle{
var id: Int!
var name: String!
init(){
self.id = 0;
self.name = ""
}
init(json: AnyObject){
if let id = json["Id"] as? Int{
self.id = id
}
if let name = json["Name"] as? String{
self.name = name
}
}
func title() -> String{
return self.name
}
}
class Profil{
var carId: Int!
var kmPerYear: Int!
var provinceId: Int!
init(carId: Int, kmPerYear: Int, provinceId: Int){
self.carId = carId;
self.kmPerYear = kmPerYear;
self.provinceId = provinceId
}
}
class FinancialEvaluation{
var batteryExpenses = 9.99
var deltaPrice = 9.99
var electricityConsomptionIn8Years = 9.99
var electricityTotalExpensesIn8Years:Double = 9.99
var electricityTotalExpensesPer100km = 9.99
var gasConsomptionIn8Years = 9.99
var gasTotalExpensesIn8Years:Double = 9.99
var gasTotalExpensesPer100km = 9.99
var millageIn8Years = 9.99
var electricityconsumptionexpensesin8years = 9.99
init(){
}
init(json:AnyObject){
if let bat = json["BatteryExpenses"] as? Double{
self.batteryExpenses = bat
}
if let bat = json["DeltaPrice"] as? Double{
self.deltaPrice = bat
}
if let bat = json["ElectricityConsumptionIn8Years"] as? Double{
self.electricityConsomptionIn8Years = bat
}
if let bat = json["ElectricityTotalExpensesIn8Years"] as? Double{
self.electricityTotalExpensesIn8Years = bat
}
if let bat = json["ElectricityTotalExpensesPer100km"] as? Double{
self.electricityTotalExpensesPer100km = bat
}
if let bat = json["GasConsumptionIn8Years"] as? Double{
self.gasConsomptionIn8Years = bat
}
if let bat = json["GasTotalExpensesIn8Years"] as? Double{
self.gasTotalExpensesIn8Years = bat
}
if let bat = json["GasTotalExpensesPer100km"] as? Double{
self.gasTotalExpensesPer100km = bat
}
if let bat = json["MileageIn8Years"] as? Double{
self.millageIn8Years = bat
}
if let bat = json["ElectricityConsumptionExpensesIn8Years"] as? Double{
self.electricityconsumptionexpensesin8years = bat
}
}
}