-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
767 lines (672 loc) · 25.9 KB
/
Copy pathProgram.cs
File metadata and controls
767 lines (672 loc) · 25.9 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
////// See https://aka.ms/new-console-template for more information
////// Base class for all people in school
////using Csharpbasic;
////class Person
////{
//// public string Name;
//// public int Age;
//// public virtual void Describe()
//// {
//// Console.WriteLine($"{Name}, {Age} years old");
//// }
////}
////// Staff can be any worker at school (not a teacher or principal)
////class Staff : Person
////{
//// public string Role;
//// public override void Describe()
//// {
//// Console.WriteLine($"{Name}, {Age}, Staff Role: {Role}");
//// }
////}
////class Cleaner : Staff
////{
//// public void IsItClean()
//// {
//// Console.WriteLine($"{Name} says it is clean.");
//// }
////}
////// Student class
////class Student : Person
////{
//// public string Grade;
//// public override void Describe()
//// {
//// Console.WriteLine($"{Name}, {Age}, Student in grade {Grade}");
//// }
////}
////class StudentwithId : Student
////{
//// public int displayId;
////}
////// Teacher base class
////class Teacher : Staff
////{
//// public virtual string Subject => "General";
//// public virtual void Teach()
//// {
//// Console.WriteLine($"{Name} is teaching {Subject}");
//// }
//// public override void Describe()
//// {
//// Console.WriteLine($"{Name}, {Age}, {Role} of {Subject}");
//// }
////}
////// Specialized teachers
////class MathTeacher : Teacher
////{
//// public override string Subject => "Math";
////}
////class EnglishTeacher : Teacher
////{
//// public override string Subject => "English";
////}
////// Principal class
////class Principal : Person
////{
//// public override void Describe()
//// {
//// Console.WriteLine($"{Name}, {Age}, School Principal");
//// }
//// public void MakeAnnouncement()
//// {
//// Console.WriteLine($"{Name} makes an important announcement.");
//// }
////}
////// Usage Example
////class Program
////{
//// static void Main()
//// {
//// Staff janitor = new Staff { Name = "Joe", Age = 50, Role = "Janitor" };
//// Student sally = new Student { Name = "Sally", Age = 15, Grade = "10th" };
//// MathTeacher mrSmith = new MathTeacher { Name = "Mr. Smith", Age = 40, Role = "Teacher" };
//// EnglishTeacher msBrown = new EnglishTeacher { Name = "Ms. Brown", Age = 32 };
//// Principal principal = new Principal { Name = "Mrs. Wilson", Age = 55 };
//// Cleaner cleaner = new Cleaner { Name = "Janitor Joe", Age = 50, Role = "Cleaner" };
//// // Describe everyone
//// janitor.Describe();
//// sally.Describe();
//// mrSmith.Describe();
//// msBrown.Describe();
//// principal.Describe();
//// // Do some actions
//// mrSmith.Teach();
//// msBrown.Teach();
//// principal.MakeAnnouncement();
//// cleaner.Describe();
//// Console.WriteLine("Enter 1 to check if it is clean:");
//// string input = Console.ReadLine();
//// if (input == "1")
//// {
//// cleaner.IsItClean();
//// }
//// }
////}
//using System.Xml.Linq;
//using static LibraryManagement;
//public class LibraryManagement
//{
// public class Person
// {
// public string Name;
// public string Surname;
// public int Age;
// public virtual void Describe()
// {
// Console.WriteLine($"{Name} {Surname} ,{Age} years old");
// }
// }
// public class Guest : Person
// {
// public override void Describe()
// {
// Console.WriteLine($"{Name} {Surname}, {Age} years old, Guest");
// }
// }
// public class Member : Person
// {
// public string Job;
// public override void Describe()
// {
// Console.WriteLine($"{Name} {Surname},{Age} years old, Member's Job: {Job}");
// }
// public List<Publication> BorrowedItems { get; set; } = new List<Publication>();
// public void ListBorrowedItems()
// {
// if (BorrowedItems.Count == 0)
// {
// Console.WriteLine($"{Name} has not borrowed ant items.");
// }
// else
// {
// Console.WriteLine($"{Name} currently has: ");
// foreach (var item in BorrowedItems)
// {
// Console.WriteLine($"-[{item.Id}]{item.SourceName} ({item.SourceType},{item.YearPublished}) ");
// }
// }
// }
// }
// public class Librarian : Member
// {
// public override void Describe()
// {
// Console.WriteLine($"{Name}, {Age} years old, Librarian");
// }
// }
// public class Publication
// {
// private static int _nextId = 1;
// private static readonly List<int> _availableIds = new();
// public int Id { get; private set; }
// public string SourceName { get; set; }
// public int YearPublished { get; set; }
// public string WriterName { get; }
// public int NumberofPage { get; }
// public string SourceType { get; }
// public Publication(string sourceName, int yearPublished, string writerName, int numberofPage, string sourceType)
// {
// if (_availableIds.Count >0)
// {
// Id = _availableIds.Min();
// _availableIds.Remove(Id);
// }
// else
// {
// Id = _nextId++;
// }
// WriterName = writerName;
// NumberofPage = numberofPage;
// SourceType = sourceType;
// SourceName = sourceName;
// YearPublished = yearPublished;
// }
// public static void ReleaseID(int id)
// {
// if (!_availableIds.Contains(id) && id>0)
// {
// _availableIds.Add(id);
// }
// }
// }
// public class Book : Publication
// {
// public Book(string sourceName, int yearPublished, string writerName, int numberofPage)
// : base(sourceName, yearPublished, writerName, numberofPage, "Book")
// {
// }
// }
// public class Journal : Publication
// {
// public Journal(string sourceName, int yearPublished, string writerName, int numberofPage)
// : base(sourceName, yearPublished, writerName, numberofPage, "Journal")
// {
// }
// }
// public class Library
// {
// public List<Publication> Publications { get; set; } = new List<Publication>();
// public Library(List<Publication> publication)
// {
// Publications = publication;
// }
// public void Borrow(Member member, List<Publication> itemsBorrow)
// {
// foreach (var item in itemsBorrow)
// {
// if (Publications.Contains(item))
// {
// Publications.Remove(item);
// member.BorrowedItems.Add(item);
// Console.WriteLine($"{member.Name} borrowed {item.SourceName} ({item.SourceType}-{item.YearPublished})");
// }
// else
// {
// Console.WriteLine($"{item.SourceName} is not available in the library.");
// }
// }
// }
// public void Return(Member member, List<Publication> itemsToReturn)
// {
// foreach (var item in itemsToReturn)
// {
// if (member.BorrowedItems.Contains(item))
// {
// member.BorrowedItems.Remove(item);
// Publications.Add(item);
// Console.WriteLine($"{member.Name} returned {item.SourceName} ({item.SourceType}-{item.YearPublished})");
// }
// else
// {
// Console.WriteLine($"{member.Name} does not have {item.SourceName} to return.");
// }
// }
// }
// public void AvailableItems()
// {
// foreach (var item in Publications)
// {
// Console.WriteLine($"[{item.Id}]{item.SourceName} ({item.YearPublished})");
// }
// }
// public Publication FindPublicationById(int id)
// {
// return Publications.FirstOrDefault(p => p.Id == id);
// }
// }
//}
//public class Program
//{
// static LibraryManagement.Library library;
// static LibraryManagement.Member currentMember;
// static List<LibraryManagement.Publication> Publications = new();
// static List<LibraryManagement.Member> members = new();
// static List<LibraryManagement.Librarian> librarians = new();
// public static void ManualDisplay()
// {
// LibraryManagement.Member hasan = new LibraryManagement.Member { Name = "Hasan", Age = 22, Job = "Student" };
// LibraryManagement.Member MrSmith = new LibraryManagement.Member { Name = "Mr. Smith", Age = 41, Job = "Teacher" };
// LibraryManagement.Librarian librarian = new LibraryManagement.Librarian { Name = "Alessandro", Age = 34, Job = "Librarian" };
// LibraryManagement.Member janitor = new LibraryManagement.Member { Name = "Bernardi", Age = 27, Job = "Janitor" };
// LibraryManagement.Book book = new LibraryManagement.Book("C# Programming", 2023, "John Doe", 300);
// LibraryManagement.Book book1 = new LibraryManagement.Book("Kürk Mantolu Madonna", 1945, "Sabahattin Ali", 201);
// LibraryManagement.Journal journal = new LibraryManagement.Journal("Tech Innovations", 2022, "Jane Smith", 50);
// LibraryManagement.Journal journal1 = new LibraryManagement.Journal("Science Today", 2023, "Dr. Emily", 30);
// LibraryManagement.Guest guest = new LibraryManagement.Guest { Name = "Fatima", Age = 21 };
// LibraryManagement.Book book2 = new LibraryManagement.Book("Kumarbaz", 1800, "Dostoyevski", 326);
// LibraryManagement.Book book3 = new LibraryManagement.Book("Test", 1999, "Mert", 100);
// var initialBooks = new List<LibraryManagement.Publication> { book, book1, book2, journal, journal1 };
// LibraryManagement.Library library = new LibraryManagement.Library(initialBooks);
// Console.WriteLine("Initial publications in the library: ");
// library.AvailableItems();
// library.Borrow(hasan, new List<LibraryManagement.Publication> { book, journal });
// library.Borrow(MrSmith, new List<LibraryManagement.Publication> { book1 });
// Console.WriteLine("\nAvailable publications after borrowing: ");
// library.AvailableItems();
// library.Return(hasan, new List<LibraryManagement.Publication> { book });
// Console.WriteLine("\nAvailable publications after returning: ");
// library.AvailableItems();
// hasan.ListBorrowedItems();
// MrSmith.ListBorrowedItems();
// }
// static void Main()
// {
// InitialMembers();
// InıtialPublications();
// while (true)
// {
// //Console.Clear();
// Console.WriteLine("=== City Library ===");
// Console.WriteLine("1) Guest 2) Member 3) Librarian 4) Exit");
// Console.Write(">");
// var choice = Console.ReadLine();
// switch (choice)
// {
// case "1":
// GuestMenu();
// break;
// case "2":
// MemberMenu();
// break;
// case "3":
// LibrarianMenu();
// break;
// case "4":
// return;
// default:
// Pause("Invalid choice, please try again.");
// break;
// }
// }
// }
// static void Pause(string msg = "Press any key to continue ...")
// {
// Console.WriteLine(msg);
// Console.ReadLine();
// }
// static void InıtialPublications()
// {
// Publications.Add(new Publication("C# Programming", 2023, "John Doe", 300, "Book"));
// Publications.Add(new Publication("Kürk Mantolu Madonna", 1945, "Sabahattin Ali", 201, "Book"));
// Publications.Add(new Publication("Science Today", 2023, "Dr. Emily", 30, "Journal"));
// library = new LibraryManagement.Library(Publications);
// }
// static void InitialMembers()
// {
// members.Add(new Member { Name = "Hasan", Surname = "Çoban", Age = 22, Job = "Student" });
// members.Add(new Member { Name = "Mr. Smith", Surname = "Johnson", Age = 41, Job = "Teacher" });
// librarians.Add(new Librarian { Name = "Alessandro", Surname = "Rossi", Age = 34, Job = "Librarian" });
// }
// static LibraryManagement.Member FindMember(string name, string surname)
// {
// return members.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && m.Surname.Equals(surname, StringComparison.OrdinalIgnoreCase));
// }
// static LibraryManagement.Librarian FindLibrarian(string name, string surname)
// {
// return librarians.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && m.Surname.Equals(surname, StringComparison.OrdinalIgnoreCase));
// }
// static void GuestMenu()
// {
// while (true)
// {
// Console.WriteLine("Welcome Guest!");
// Console.WriteLine("1) List Available 2) Search 3) Exit");
// Console.Write(">");
// var choice = Console.ReadLine();
// switch (choice)
// {
// case "1":
// ListAvailable();
// break;
// case "2":
// SearchMenu();
// break;
// case "3":
// return;
// }
// }
// }
// static void ListAvailable()
// {
// Console.WriteLine("Available Publications: ");
// foreach (var item in Publications)
// {
// Console.WriteLine($"[{item.Id}] {item.SourceName} ({item.YearPublished}) - {item.SourceType}");
// }
// }
// static List<Publication> SearchPublications(string name, string writer, int? year)
// {
// var filteredPublications = new List<Publication>();
// foreach (var item in Publications)
// {
// bool nameMatch = string.IsNullOrEmpty(name) || item.SourceName.Contains(name, StringComparison.OrdinalIgnoreCase);
// bool writerMatch = string.IsNullOrEmpty(writer) || item.WriterName.Contains(writer, StringComparison.OrdinalIgnoreCase);
// bool yearMatch = !year.HasValue || item.YearPublished == year.Value;
// if (nameMatch && writerMatch && yearMatch)
// {
// filteredPublications.Add(item);
// }
// }
// return filteredPublications;
// }
// static void SearchMenu()
// {
// Console.WriteLine("Enter book/journal name to search (or press Enter to skip): ");
// string name = Console.ReadLine();
// Console.WriteLine("Enter writer name to search (or press Enter to skip):");
// string writer = Console.ReadLine();
// Console.WriteLine("Enter year to search (or press Enter to skip):");
// string yearInput = Console.ReadLine();
// int? year = null;
// if (int.TryParse(yearInput, out int parsedYear))
// {
// year = parsedYear;
// }
// var foundBooks = SearchPublications(name, writer, year);
// if (foundBooks.Count == 0)
// {
// Console.WriteLine("No publications found matching your criteria.");
// }
// else
// {
// Console.WriteLine("Found Publications: ");
// foreach (var item in foundBooks)
// {
// Console.WriteLine($"[{item.Id}] {item.SourceName} by {item.WriterName}, published in {item.YearPublished}, Type: {item.SourceType}");
// }
// }
// }
// static void MemberMenu()
// {
// LibraryManagement.Member newMember;
// Console.WriteLine("Enter your name: ");
// var name = Console.ReadLine();
// Console.WriteLine("Enter your surname: ");
// var surname = Console.ReadLine();
// var member = FindMember(name, surname);
// if (member ==null)
// {
// Console.WriteLine("Member not found, creating a new member");
// RegisterMember();
// }
// else
// {
// Console.WriteLine($"Welcome {member.Name}");
// while (true)
// {
// Console.WriteLine($"[Member: {member.Name}]\n 1) List Available 2) Search 3) Borrow 4) Return 5) My Items 6)Describes 7) Exit ");
// Console.Write(">");
// var choice = Console.ReadLine();
// switch (choice)
// {
// case "1":
// ListAvailable();
// break;
// case "2":
// SearchMenu();
// break;
// case "3":
// BorrowItems(library, member);
// break;
// case "4":
// ReturnItems(library, member);
// break;
// case "5":
// ShowMyItems(member);
// break;
// case "6":
// member.Describe();
// break;
// case "7":
// return;
// }
// }
// }
// static void BorrowItems(LibraryManagement.Library library, LibraryManagement.Member member)
// {
// Console.WriteLine("Enter the IDs of the publications you want to borrow: ");
// var input = Console.ReadLine();
// var ids = input.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
// var itemsToBorrow = new List<LibraryManagement.Publication>();
// foreach (var idStr in ids)
// {
// if (int.TryParse(idStr, out int id))
// {
// var item = library.FindPublicationById(id);
// if (item != null)
// {
// itemsToBorrow.Add(item);
// }
// else
// {
// Console.WriteLine("Publication not found.");
// }
// }
// else
// {
// Console.WriteLine("Invalid ID!");
// }
// }
// if (itemsToBorrow.Count > 0)
// {
// library.Borrow(member, itemsToBorrow);
// }
// }
// static void ReturnItems(LibraryManagement.Library library, LibraryManagement.Member member)
// {
// Console.WriteLine("Enter the IDs of the publications you want to return: ");
// if (int.TryParse(Console.ReadLine(), out int returnid))
// {
// var item = member.BorrowedItems.FirstOrDefault(p => p.Id==returnid);
// if (item != null)
// {
// library.Return(member, new List<LibraryManagement.Publication> { item });
// }
// else
// {
// Console.WriteLine("Publication not found.");
// }
// }
// else
// {
// Console.WriteLine("Invalid ID!");
// }
// }
// static void ShowMyItems(LibraryManagement.Member member)
// {
// if (member.BorrowedItems.Count == 0)
// {
// Console.WriteLine("You have not borrowed ant items.");
// }
// else
// {
// Console.WriteLine("You currently have: ");
// foreach (var item in member.BorrowedItems)
// {
// Console.WriteLine($"[{item.Id}] {item.SourceName} ({item.SourceType}-{item.YearPublished})");
// }
// }
// }
// }
// static void LibrarianMenu()
// {
// LibraryManagement.Librarian librarian;
// Console.WriteLine("Enter your name: ");
// var name = Console.ReadLine();
// Console.WriteLine("Enter your surname: ");
// var surname = Console.ReadLine();
// var librarians = FindLibrarian(name, surname);
// if (librarians ==null)
// {
// Console.WriteLine("Librarian not found,try again...");
// }
// else
// {
// Console.WriteLine($"Welcome {librarians.Name}");
// while (true)
// {
// Console.WriteLine("[Librarian Menu]");
// Console.WriteLine("1) Add Publication 2) Remove Publication 3) register Member 4) List Publications 5) Exit ");
// Console.Write(">");
// var console = Console.ReadLine();
// switch (console)
// {
// case "1":
// AddPublication();
// break;
// case "2":
// RemovePublication();
// break;
// case "3":
// RegisterMember();
// break;
// case "4":
// ListAvailable();
// break;
// case "5":
// return;
// }
// }
// }
// static void AddPublication()
// {
// while (true)
// {
// Console.WriteLine("If you want to exit adding publication, enter '0' at any time.");
// if (Console.ReadLine() == "0")
// {
// Console.WriteLine("Exiting publication addition...");
// break;
// }
// Console.WriteLine("Title: ");
// var title = Console.ReadLine();
// Console.WriteLine("Writer: ");
// var writer = Console.ReadLine();
// int year;
// while (true)
// {
// Console.WriteLine("Year: ");
// if (int.TryParse(Console.ReadLine(), out year))
// {
// break;
// }
// Console.WriteLine("Invalid year, please enter a valid year. ");
// }
// int pages;
// while (true)
// {
// Console.WriteLine("Number of pages: ");
// if (int.TryParse(Console.ReadLine(), out pages) && pages > 0)
// {
// break;
// }
// Console.WriteLine("Invalid number of pages, please enter a valid number of pages.");
// }
// Console.WriteLine("Type (Book/Journal): ");
// var type = Console.ReadLine();
// LibraryManagement.Publication newPublication;
// if (type.Equals("Book", StringComparison.OrdinalIgnoreCase))
// {
// newPublication = new LibraryManagement.Book(title, year, writer, pages);
// }
// else if (type.Equals("Journal", StringComparison.OrdinalIgnoreCase))
// {
// newPublication = new LibraryManagement.Journal(title, year, writer, pages);
// }
// else
// {
// Console.WriteLine("Invalid type, please enter 'Book' or 'Journal'.");
// continue;
// }
// library.Publications.Add(newPublication);
// Console.WriteLine($"{newPublication.SourceName} has been added to the library.");
// }
// }
// static void RemovePublication()
// {
// while (true)
// {
// Console.WriteLine("If you want to exit removing publication, enter '0' at any time.");
// if (Console.ReadLine() == "0")
// {
// Console.WriteLine("Exiting publication removal...");
// break;
// }
// Console.WriteLine("Enter the name of the publication to remove: ");
// var name = Console.ReadLine();
// var publicationToRemove = library.Publications.FirstOrDefault(p => p.SourceName.Equals(name, StringComparison.OrdinalIgnoreCase));
// if (publicationToRemove != null)
// {
// Publication.ReleaseID(publicationToRemove.Id);
// library.Publications.Remove(publicationToRemove);
// Console.WriteLine($"{publicationToRemove.SourceName} has been removed from the library.");
// }
// else
// {
// Console.WriteLine("Publication not found.");
// }
// }
// }
// }
// static void RegisterMember()
// {
// LibraryManagement.Member newMember;
// Console.WriteLine("Name: ");
// var newName = Console.ReadLine();
// Console.WriteLine("Surname:");
// var newSurname = Console.ReadLine();
// Console.WriteLine("Job: ");
// var newJob = Console.ReadLine();
// Console.WriteLine("Age: ");
// var newAgeInput = Console.ReadLine();
// int? newAge = null;
// if (int.TryParse(newAgeInput, out int parsedAge))
// {
// newAge = parsedAge;
// newMember = new LibraryManagement.Member { Name = newName, Surname = newSurname, Age = (int)newAge, Job = newJob };
// members.Add(newMember);
// Console.WriteLine($" New member {newMember.Name} {newMember.Surname} has been created.");
// }
// }
//}