Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ex_2
- {
- public class Book
- {
- #region Переменные
- private string autor_;
- public string autor
- {
- set
- {
- if (value == null)
- { throw new ArgumentException("Неверный ввод имени автора"); }
- else autor_ = value;
- }
- get
- {
- return autor_;
- }
- }
- private string nameBook_;
- public string nameBook
- {
- set
- {
- if (value == null)
- { throw new ArgumentException("Неверный ввод названия книги"); }
- else nameBook_ = value;
- }
- get
- {
- return nameBook_;
- }
- }
- private string janr_;
- public string janr
- {
- set
- {
- if (value == null)
- { throw new ArgumentException("Неверный ввод жанра"); }
- else janr_ = value;
- }
- get
- {
- return janr_;
- }
- }
- #endregion
- public Book(string autorIn, string nameBookIn, string janrIn)
- {
- autor = autorIn;
- nameBook = nameBookIn;
- janr = janrIn;
- }
- public override string ToString()
- {
- return $"Название книги {nameBook}. Имя автора {autor}. Жанр {janr}. ";
- }
- }
- public class Record
- {
- public Book book;
- public int timeGet;
- public Record(Book b1, int timeGet1)
- {
- book = b1;
- timeGet = timeGet1;
- }
- }
- public class Person
- {
- private string name_;
- private string numberTelephone_;
- public string name
- {
- set
- {
- if (value == null)
- { throw new ArgumentException("Неверный ввод имени"); }
- else name_ = value;
- }
- get
- {
- return name_;
- }
- }
- public string numberTelephone
- {
- set
- {
- if (value.Length > 11)
- { throw new ArgumentException("Неверный ввод номера телефона"); }
- else numberTelephone_ = value;
- }
- get
- {
- return numberTelephone_;
- }
- }
- public Person(string nameIn, string numberTelephoneIn)
- {
- name = nameIn;
- numberTelephone = numberTelephoneIn;
- }
- public override string ToString()
- {
- return $"Имя: {name}. Номер телефона {numberTelephone}";
- }
- public void Reply(object sender, EventArgs e)
- {
- Console.WriteLine($"{sender}, у Вас задолженность в библиотеке");
- Random rand = new Random();
- string[] str = { "Да", "Обязательно", "Cкоро приду", "Сегодня не могу", "На следующей неделе"};
- int randInt = rand.Next(0, 4);
- Console.WriteLine(str[randInt]);
- }
- }
- public delegate void Delegate(object sender, EventArgs e);
- public class Library
- {
- public List<Book> listBooks = new List<Book>();
- private Dictionary<Person, List<Record>> cartoteka = new Dictionary<Person, List<Record>>();
- private EventArgs e;
- public event Delegate Notify;
- public bool Add(Person person)
- {
- if(cartoteka.ContainsKey(person))
- {
- return false;
- }
- cartoteka.Add(person, new List<Record>());
- Notify += person.Reply;
- return true;
- }
- public IEnumerable<Book> GetBook(string category)
- {
- IEnumerable<Book> temp = listBooks.FindAll(x => x.janr == category);
- return temp;
- }
- public bool Give(Book book, Person person)
- {
- if(listBooks.Contains(book))
- {
- Add(person);
- Random rnd = new Random();
- Record record = new Record(book, rnd.Next(1, 24));
- cartoteka[person].Add(record);
- return true;
- }
- return false;
- }
- public void CheckReaders()
- {
- List<Record> listRecords = new List<Record>();
- Console.WriteLine("Введите номер сегодняшнего дня в году");
- int day = int.Parse(Console.ReadLine());
- foreach(var item in cartoteka)
- {
- listRecords = item.Value;
- for (int i = 0; i < listRecords.Count; i++)
- {
- if(day - listRecords[i].timeGet > 14)
- {
- Notify(item.Key, e);
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement