Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace Animals
- {
- public class Animal
- {
- private string name;
- private int age;
- private string gender;
- public Animal(string name, int age, string gender)
- {
- this.name = name;
- this.Age = age;
- this.gender = gender;
- }
- public string Name
- {
- get => this.name;
- private set
- {
- if (value == null)
- {
- throw new ArgumentException("Invalid input!");
- }
- this.name = value;
- }
- }
- public int Age
- {
- get => this.age;
- private set
- {
- if (value <= 0)
- {
- throw new ArgumentException("Invalid input!");
- }
- this.age = value;
- }
- }
- public string Gender
- {
- get => this.gender;
- private set
- {
- if (value == null)
- {
- throw new ArgumentException("Invalid input!");
- }
- this.gender = value;
- }
- }
- public virtual void ProduceSound()
- {
- Console.WriteLine("Produce sound");
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.AppendLine($"{this.Name} {this.Age} {this.Gender}");
- return sb.ToString().TrimEnd();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement