Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Arrays
- {
- class Chicken
- {
- //полета: име, възраст, брой яйца
- private string name;
- private int age;
- private int countEggs;
- //конструктор
- public Chicken (string name, int age, int countEggs)
- {
- this.Name = name;
- this.Age = age;
- this.CountEggs = countEggs;
- }
- //getters и setters
- public string Name
- {
- get { return this.name; }
- set {
- //валидация на името -> value -> 1. != null 2. != empty
- if (String.IsNullOrEmpty(value))
- {
- throw new Exception("Name cannot be empty.");
- }
- this.name = value;
- }
- }
- public int Age
- {
- get { return this.age; }
- set {
- //валидация на възрастта -> между 0 и 15
- if (value < 0 || value > 15)
- {
- throw new Exception("Age should be between 0 and 15.");
- }
- this.age = value;
- }
- }
- public int CountEggs
- {
- get { return this.countEggs; }
- set { this.countEggs = value; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment