forked from nastia3995/TaskRefactoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassLibrary1.cs
More file actions
368 lines (352 loc) · 11.1 KB
/
ClassLibrary1.cs
File metadata and controls
368 lines (352 loc) · 11.1 KB
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1
{
public class Person
{
private string name;
private string surname;
private int birthDay;
private int birthMonth;
private int birthYear;
public Person()
{
}
public Person(string Name, string Surname, int BirthDate, int BirthMonth, int BirthYear)
{
name = Name;
surname = Surname;
birthDay = BirthDate;
birthMonth = BirthMonth;
birthYear = BirthYear;
}
public Person(string Name, string Surname)
{
name = Name;
surname = Surname;
}
public string Name
{
set
{
if (value != null || value.Length > 2)
{
name = value;
}
}
get
{
return name;
}
}
public string Surname
{
set
{
if (value != null || value.Length > 2)
{
surname = value;
}
}
get
{
return surname;
}
}
public int BirthDay
{
set
{
if (value != 0)
{
birthDay = value;
}
}
get
{
return birthDay;
}
}
public int BirthMonth
{
set
{
if (value != 0)
{
birthMonth = value;
}
}
get
{
return birthMonth;
}
}
public int BirthYear
{
set
{
if (value != 0)
{
birthYear = value;
}
}
get
{
return birthYear;
}
}
}
public class Applicant:Person
{
private int finalExamGrade;
private double schoolGrade;
private string schoolName;
public Applicant()
{
}
public Applicant(string Name, string Surname, int BirthDate, int BirthMonth, int BirthYear, int FinalExamGrade, double SchoolGrade, string SchoolName):base(Name, Surname, BirthDate, BirthYear, BirthMonth)
{
finalExamGrade = FinalExamGrade;
schoolGrade = SchoolGrade;
schoolName = SchoolName;
}
public Applicant(int FinalExamGrade)
{
finalExamGrade = FinalExamGrade;
}
public int FinalExamGrade
{
set { if(value>0&&value<201)
finalExamGrade=value;
}
get { return finalExamGrade; }
}
public double SchoolGrade
{
set
{
if (value > 0 && value <=12)
schoolGrade=value;
}
get { return schoolGrade; }
}
public string SchoolName
{
set { if(value != null)
schoolName=value;}
get
{
return schoolName;
}
}
}
public class Student : Person
{
private int course;
private string group;
private string faculty;
private string universityName;
public Student()
{
}
public Student(string Name, string Surname, int BirthDate, int BirthMonth, int BirthYear, int course, string group, string faculty, string universityName) : base(Name, Surname, BirthDate, BirthYear, BirthMonth)
{
this.course = course;
this.group = group;
this.faculty = faculty;
this.universityName = universityName;
}
public Student(int course)
{
this.course=course;
}
public int Course
{
set
{
if(value>0&&value<7) course = value;
}
get
{
return course;
}
}
public string Group
{
set { group = value; }
get
{
return group;
}
}
public string Faculty { set { faculty = value; }
get
{return faculty;
}
}
public string UniversityName
{
set { universityName = value; }
get
{
return universityName;
}
}
}
public class Professor : Person
{
private string position;
private string chair;
private string universityName;
public Professor()
{
}
public Professor(string Name, string Surname, int BirthDate, int BirthMonth, int BirthYear, string position, string chair, string universityName) : base(Name, Surname, BirthDate, BirthYear, BirthMonth)
{
this.position = position;
this.chair = chair;
this.universityName = universityName;
}
public Professor(string position)
{
this.position = position;
}
public string Position
{
set
{
position = value;
}
get
{
return position;
}
}
public string Chair
{
set { chair = value; }
get
{
return chair;
}
}
public string UniversityName
{
set { universityName = value; }
get
{
return universityName;
}
}
}
public class LibraryUser : Person
{
public LibraryUser() { }
public LibraryUser(string Name, string Surname, int BirthDate, int BirthMonth, int BirthYear, int idReaderCard, DateTime issue, int cost):base(Name, Surname, BirthDate, BirthMonth, BirthYear)
{
this.idReaderCard = idReaderCard;
this.cost = cost;
this.issue = issue;
}
public int idReaderCard
{
set;get;
}
public DateTime issue { set; get; }
public int cost { set; get; }
}
public static class UserInput
{
public static string GetString(string message)
{
Console.Write(message);
return Console.ReadLine();
}
public static int GetInt(string message)
{
int value;
while (true)
{
Console.Write(message);
if (int.TryParse(Console.ReadLine(), out value))
return value;
Console.WriteLine("Ошибка: введите целое число!");
}
}
public static DateTime GetDate(string message)
{
DateTime date;
while (true)
{
Console.Write(message);
string input = Console.ReadLine();
if (DateTime.TryParseExact(input, "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
return date;
Console.WriteLine("Ошибка: введите дату в формате dd.MM.yyyy!");
}
}
}
public static class DataValidator
{
public static bool IsValidName(string name)
{
return !string.IsNullOrWhiteSpace(name) && name.Length >= 2;
}
}
public static class EntityFactory
{
public static Student CreateStudent()
{
string name = UserInput.GetString("Enter name of the student: ");
string surname = UserInput.GetString("Enter surname of the student: ");
int birthday = UserInput.GetInt("Enter day of birth: ");
int birthMonth = UserInput.GetInt("Enter month of birth: ");
int birthYear = UserInput.GetInt("Enter year of birth: ");
int course = UserInput.GetInt("Enter year of studying: ");
string group = UserInput.GetString("Enter name of the group: ");
string faculty = UserInput.GetString("Enter name of the faculty: ");
string university = UserInput.GetString("Enter name of the university: ");
return new Student(name, surname, birthday, birthMonth, birthYear, course, group, faculty, university);
}
public static Applicant CreateApplicant()
{
string name = UserInput.GetString("Enter name of the applicant: ");
string surname = UserInput.GetString("Enter surname of the applicant: ");
int birthday = UserInput.GetInt("Enter day of birth: ");
int birthMonth = UserInput.GetInt("Enter month of birth: ");
int birthYear = UserInput.GetInt("Enter year of birth: ");
int finalExamGrade = UserInput.GetInt("Enter the ZNO grade: ");
int schoolGrade = UserInput.GetInt("Enter the number of points for a document: ");
string schoolName = UserInput.GetString("Enter name of the school: ");
return new Applicant(name, surname, birthday, birthMonth, birthYear, finalExamGrade, schoolGrade, schoolName);
}
public static Professor CreateProfessor()
{
string name = UserInput.GetString("Enter name of the professor: ");
string surname = UserInput.GetString("Enter surname of the professor: ");
int birthday = UserInput.GetInt("Enter day of birth: ");
int birthMonth = UserInput.GetInt("Enter month of birth: ");
int birthYear = UserInput.GetInt("Enter year of birth: ");
string position = UserInput.GetString("Enter position: ");
string chair = UserInput.GetString("Enter chair name: ");
string university = UserInput.GetString("Enter university name: ");
return new Professor(name, surname, birthday, birthMonth, birthYear, position, chair, university);
}
public static LibraryUser CreateLibraryUser()
{
string name = UserInput.GetString("Enter name of the library user: ");
string surname = UserInput.GetString("Enter surname of the library user: ");
int birthday = UserInput.GetInt("Enter day of birth: ");
int birthMonth = UserInput.GetInt("Enter month of birth: ");
int birthYear = UserInput.GetInt("Enter year of birth: ");
DateTime issueDate = UserInput.GetDate("Enter issue date (dd.MM.yyyy): ");
int idReaderCard = UserInput.GetInt("Enter reader card id: ");
int cost = UserInput.GetInt("Enter monthly cost: ");
return new LibraryUser(name, surname, birthday, birthMonth, birthYear, idReaderCard, issueDate, cost);
}
}
}