AmidamaruZXC

Untitled

Jun 17th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace BookstoreLibrary
  8. {
  9.     public class Book : Product
  10.     {
  11.         private short _numberOfPages;
  12.         private short _year;
  13.         private double _rating;
  14.  
  15.         public short NumberOfPages
  16.         {
  17.             get => _numberOfPages;
  18.             set
  19.             {
  20.                 if (value > 0)
  21.                     _numberOfPages = value;
  22.                 else
  23.                     throw new ArgumentException("Количество страниц должно быть положительным!");
  24.             }
  25.         }
  26.  
  27.         public short Year
  28.         {
  29.             get => _year;
  30.             set
  31.             {
  32.                 if (value >= 1990 && value <= 2020)
  33.                     _year = value;
  34.                 else
  35.                     throw new ArgumentException("Год издания книги должен принимать значение в диапазоне [1990, 2020]");
  36.             }
  37.         }
  38.  
  39.         public double Rating
  40.         {
  41.             get => _rating;
  42.             set
  43.             {
  44.                 if (value >= 0 && value < 5)
  45.                     _rating = value;
  46.                 else
  47.                     throw new ArgumentException("Рейтинг книги должен принимать значение в диапазоне [0, 5)");
  48.             }
  49.         }
  50.  
  51.         public string GetShortInfo()
  52.         {
  53.             return "";
  54.         }
  55.  
  56.         public override string ToString()
  57.         {
  58.             return base.ToString() + GetShortInfo();
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment