Advertisement
Guest User

Untitled

a guest
Nov 5th, 2021
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System;
  2.  
  3. namespace AnimalFarm.Models
  4. {
  5. public class Chicken
  6. {
  7. private const int MinAge = 0;
  8. private const int MaxAge = 15;
  9.  
  10. private string name;
  11. private int age;
  12.  
  13. public Chicken(string name, int age)
  14. {
  15. this.Name = name;
  16. this.Age = age;
  17. }
  18.  
  19. public string Name
  20. {
  21. get => this.name;
  22. private set
  23. {
  24. if (string.IsNullOrEmpty(value))
  25. {
  26. throw new ArgumentException("Name cannot be empty.");
  27. }
  28. this.name = value;
  29. }
  30. }
  31.  
  32. public int Age
  33. {
  34. get => this.age;
  35.  
  36. private set
  37. {
  38. if (value < MinAge || value > MaxAge)
  39. {
  40. throw new ArgumentException($"Age should be between {MinAge} and {MaxAge}.");
  41. }
  42.  
  43. this.age = value;
  44. }
  45. }
  46.  
  47. public double ProductPerDay
  48. {
  49. get
  50.  
  51. {
  52. return CalculateProductPerDay();
  53. }
  54. }
  55.  
  56. private double CalculateProductPerDay()
  57. {
  58. switch (this.Age)
  59. {
  60. case 0:
  61. case 1:
  62. case 2:
  63. case 3:
  64. return 1.5;
  65. case 4:
  66. case 5:
  67. case 6:
  68. case 7:
  69. return 2;
  70. case 8:
  71. case 9:
  72. case 10:
  73. case 11:
  74. return 1;
  75. default:
  76. return 0.75;
  77. }
  78. }
  79. }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement