-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefiningClasses1
308 lines (291 loc) · 7.97 KB
/
DefiningClasses1
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class GSM
{
private string model;
private string manufacturer;
private double price = 0.37;
private string owner;
private char iPhone4S;
public GSM(string model, string manufacturer)
{
this.Model=model;
this.Manufacturer = manufacturer;
this.Price = 0;
this.Owner = null;
}
public GSM(string model, string manufacturer, double price, bool iPhone)
{
this.Model = model;
this.Manufacturer = manufacturer;
this.Price = price;
this.Owner = null;
}
public GSM(string model, string manufacturer, string owner, bool iPhone)
{
this.Model = model;
this.Manufacturer = manufacturer;
this.Price = 0;
this.Owner = owner;
}
public GSM(string model, string manufacturer, double price, string owner, bool iPhone)
{
this.Model = model;
this.Manufacturer = manufacturer;
this.Price = price;
this.Owner = owner;
}
public override string ToString()
{
return ("Model: " + this.model + "\n" + "Manufacturer: " + this.manufacturer + "\n" + "Price: " + this.price + "$" + "\n" + "Owner: " + this.owner + "\n" + "Is iPhone: " + this.IPhone + "\n");
}
public string Model
{
get { return this.model; }
set { this.model = value; }
}
public string Manufacturer
{
get { return this.manufacturer; }
set { this.manufacturer = value; }
}
public double Price
{
get { return this.price; }
set
{
if (value < 0)
{
throw new ArgumentException("Price cannot be negative!");
}
else this.price = value; }
}
public string Owner
{
get { return this.owner; }
set { this.owner = value; }
}
public char IPhone
{
get { return this.iPhone4S; }
set { this.iPhone4S = value; }
}
public List<Call> CallHistory = new List<Call>();
public void AddCall (string phonenumber, double duration)
{
CallHistory.Add(new Call(phonenumber, duration));
}
public void RemoveCall(List<Call> AllCalls, string phonenumber, int duration)
{
if (AllCalls.Exists(element => element.Phonenumber == phonenumber))
{
}
}
public void ClearCallHistory(List<Call> AllCalls)
{
AllCalls.Clear();
}
public double CalculatePrice(List<Call> AllCalls, double price = 0.37)
{
double sum = 0;
foreach (Call currentCall in AllCalls)
{
sum += currentCall.Duration * price;
}
return sum;
}
}
class Battery
{
private string model;
private double hoursidle;
private double hourstalk;
private enum BatteryType {LiIon, NiMH, NiCd};
public Battery(string model)
{
this.Model = model;
this.Hoursidle = 0;
this.Hourstalk = 0;
}
public Battery(string model, double hoursidle)
{
this.Model = model;
this.Hoursidle = hoursidle;
this.Hourstalk = 0;
}
public Battery(string model, double hoursidle, double hourstalk)
{
this.Model = model;
this.Hoursidle = hoursidle;
this.Hourstalk = hourstalk;
}
public string Model
{
get { return this.model; }
set { this.model = value; }
}
public double Hoursidle
{
get { return this.hoursidle; }
set { this.hoursidle = value; }
}
public double Hourstalk
{
get { return this.hourstalk; }
set { this.hourstalk = value; }
}
}
class Display
{
private double size;
private int colors;
public Display()
{
this.Size = 0;
this.Colors = 0;
}
public Display(double size, int colors)
{
this.Size = size;
this.Colors = colors;
}
public double Size
{
get { return this.size; }
set { this.size = value; }
}
public int Colors
{
get { return this.colors; }
set
{
if (colors <= 0)
{
throw new ArgumentException("Colors cannot be 0 or negative!");
}
else this.colors = value;
}
}
}
class Call
{
private int day;
private string time;
private string phonenumber;
private double duration;
public Call(string phonenumber, double duration)
{
this.day = DateTime.Now.Day;
this.time = DateTime.Now.ToShortTimeString();
this.Phonenumber = phonenumber;
this.Duration = duration;
}
public string Phonenumber
{
get { return this.phonenumber; }
set { this.phonenumber = value; }
}
public double Duration
{
get { return this.duration; }
set { this.duration = value; }
}
public override string ToString()
{
return ("Date: " + this.day + "\n" + "Time: " + this.time + "\n" + "Phone dialed: " + this.phonenumber + "\n" + "Duration: " + this.duration + "\n");
}
}
class GSMCallHistoryTest
{
static GSM GSMInput()
{
Console.WriteLine("Enter model: ");
string model = Console.ReadLine();
Console.WriteLine("Enter manufacturer: ");
string manufacturer = Console.ReadLine();
GSM currentGSM = new GSM(model, manufacturer);
Console.WriteLine("Enter price or 0: ");
double price = double.Parse(Console.ReadLine());
Console.WriteLine("Enter owner or 0: ");
string owner = Console.ReadLine();
Console.WriteLine("Is it iPhone? Y/N: ");
currentGSM.IPhone = (Console.ReadLine() == "Y") ? 'Y' : 'N';
if (price != 0)
{
currentGSM.Price = price;
}
if (owner != "0")
{
currentGSM.Owner = owner;
}
return currentGSM;
}
static GSM[] GSMTest()
{
Console.WriteLine("How many GSMs u want to input? ");
int n = int.Parse(Console.ReadLine());
GSM[] GSMarr = new GSM[n];
for (int i = 0; i < n; i++)
{
GSMarr[i] = GSMInput();
}
for (int i = 0; i < n; i++)
{
Console.WriteLine(GSMarr[i]);
}
return GSMarr;
}
static List<Call> PerformCalls()
{
Console.WriteLine("How many calls do you wish to perform?");
int n = int.Parse(Console.ReadLine());
List<Call> Callarray = new List<Call>();
for (int i = 0; i < n; i++)
{
Console.WriteLine("Call number " + (i+1));
Console.WriteLine("To which phone number? ");
string phonenumber = Console.ReadLine();
Console.WriteLine("What duration? ");
double duration = double.Parse(Console.ReadLine());
Callarray.Add(new Call(phonenumber, duration));
Console.WriteLine();
}
for (int i = 0; i < n; i++)
{
Console.WriteLine(Callarray[i]);
}
return Callarray;
}
static List<Call> RemoveLongest(List<Call> calls)
{
double max = 0;
int index = 0;
for (int i = 0; i < calls.Count; i++)
{
if (calls[i].Duration > max)
{
max = calls[i].Duration;
index = i;
}
}
calls[index].Duration = 0;
return calls;
}
static void Main()
{
GSM[] GSMarray = GSMTest();
List<Call> Callarray = PerformCalls();
Console.WriteLine("Total price: " + GSMarray[0].CalculatePrice(Callarray));
Callarray = RemoveLongest(Callarray);
Console.WriteLine("Price without longest call: " + GSMarray[0].CalculatePrice(Callarray));
GSMarray[0].ClearCallHistory(Callarray);
Console.WriteLine();
for (int i = 0; i < Callarray.Count; i++)
{
Console.WriteLine(Callarray[i]);
}
}
}