Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Elephant
- {
- public string name { get; private set; }
- public uint age { get; private set; }
- public uint hunger { get; private set; }
- public Elephant(string name, uint age)
- {
- this.name = name;
- this.age = age;
- this.hunger = 0;
- }
- public void Eat(uint foodCount)
- {
- if (foodCount > hunger) hunger = 0;
- else hunger -= foodCount;
- Console.WriteLine("We fed {0} with {1} brickets of food [hunger {2}]", name, foodCount, hunger);
- }
- public void Shit()
- {
- hunger += 50;
- Console.WriteLine("{0} shits well [hunger {1}]", name, hunger);
- }
- public override string ToString()
- {
- string temp = "satisfied";
- if (hunger > 20) temp = "hungry";
- if (hunger > 50) temp = "starving";
- if (hunger > 100) temp = "starved to death";
- return string.Format("{0}, {1} years old. Elephant is {2}", name, age, temp);
- }
- }
- class ElephantFarm : List<Elephant>
- {
- public void AddElephant(string name, uint age)
- {
- this.Add(new Elephant(name, age));
- }
- public void FindSmallestElephant()
- {
- uint minimalAge = this.Min(o => o.age);
- int smallestElephantIndex = this.FindIndex(o => o.age == minimalAge);
- Console.WriteLine("We found smallest elephant, {0} y.o.", minimalAge);
- this[smallestElephantIndex].Shit();
- this[smallestElephantIndex].Eat(minimalAge * 5);
- Console.WriteLine("Smallest elephant {0}", this[smallestElephantIndex].ToString());
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- ElephantFarm farm = new ElephantFarm();
- farm.AddElephant("Rickey", 18);
- farm.AddElephant("Conroy", 3);
- farm.AddElephant("Jackson", 21);
- farm.AddElephant("Piwi", 5);
- farm.AddElephant("Dave", 11);
- farm.FindSmallestElephant();
- Console.ReadKey(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement