namespace Hierarchy { public abstract class Food { public int Quantity { get; set; }…
- User
namespace Hierarchy { public abstract class Food { public int Quantity { get; set; }
public Food(int quantity) { this.Quantity = quantity; } } public class Vegetable : Food { public Vegetable(int quantity) : base(quantity) { } } public class Meat : Food { public Meat(int quantity) : base(quantity) { } } public abstract class Animal { public string AnimalType { get; set; } public string AnimalName { get; set; } public double AnimalWeight { get; set; } public int FoodEaten { get; set; } public string LivingRegion { get; set; } protected Animal(string animalType, string animalName, double animalWeight, string livingRegion) { this.AnimalType = animalType; this.AnimalName = animalName; this.AnimalWeight = animalWeight; this.LivingRegion = livingRegion; this.FoodEaten = 0; } public abstract void MakeSound(); public virtual void Eat(Food food) { this.FoodEaten += food.Quantity; } } public abstract class Mammal : Animal { protected Mammal(string animalType, string animalName, double animalWeight, string livingRegion) : base(animalType, animalName, animalWeight, livingRegion) { } } public class Mouse : Mammal { public Mouse(string animalName, double animalWeight, string livingRegion) : base("Mouse", animalName, animalWeight, livingRegion) { } public override void MakeSound() { Console.WriteLine("SQUEEEAAAK!"); } public override void Eat(Food food) { if (food is Vegetable) { base.Eat(food); Console.WriteLine($"Eaten {FoodEaten} peaces of {food.GetType().Name}"); } else Console.WriteLine("{0}s are not eating that type of food!", this.AnimalType); } } public class Zebra : Mammal { public Zebra(string animalName, double animalWeight, string livingRegion) : base("Zebra", animalName, animalWeight, livingRegion) { } public override void MakeSound() { Console.WriteLine("Zs"); } public override void Eat(Food food) { if (food is Vegetable) base.Eat(food); else Console.WriteLine("{0}s are not eating that type of food!", this.AnimalType); } } public abstract class Feline : Animal { protected Feline(string animalType, string animalName, double animalWeight, string livingRegion) : base(animalType, animalName, animalWeight, livingRegion) { } } public class Cat : Feline { private string breed; public Cat(string animalName, double animalWeight, string livingRegion, string breed) : base("Cat", animalName, animalWeight, livingRegion) { this.breed = breed; } public override void MakeSound() { Console.WriteLine("Meowwww"); } public override string ToString() { return $"{this.AnimalType}[{this.AnimalName}, {this.breed}, {this.AnimalWeight:F1}, {this.LivingRegion}, {this.FoodEaten}]"; } } public class Tiger : Feline { public Tiger(string animalName, double animalWeight, string livingRegion) : base("Tiger", animalName, animalWeight, livingRegion) { } public override void MakeSound() { Console.WriteLine("ROAAR!!!"); } public override void Eat(Food food) { if (food is Meat) base.Eat(food); else Console.WriteLine("{0}s are not eating that type of food!", this.AnimalType); } } class Program { static void Main(string[] args) { List<Animal> animals = new List<Animal>(); List<Food> foods = new List<Food>(); animals.Add(new Mouse("Jerry", 1.5, "Home")); animals.Add(new Zebra("Marty", 500, "Savannah")); animals.Add(new Cat("Garfield", 5, "House", "Persian")); animals.Add(new Tiger("Shere Khan", 300, "Jungle")); foods.Add(new Vegetable(4)); //Console.WriteLine("Please input: Animal type, name, weigth, living region"); //Console.WriteLine("Input food, quantity"); string input = Console.ReadLine(); while (input != "End") { string[] animalInfo = input.Split(" "); string[] foodInfo = Console.ReadLine().Split(" "); Animal animal = null; Food food = null; string animalType = animalInfo[0]; string animalName = animalInfo[1]; double animalWeight = double.Parse(animalInfo[2]); string livingRegion = animalInfo[3]; switch (animalType) { case "Mouse": animal = new Mouse(animalName, animalWeight, livingRegion); break; case "Zebra": animal = new Zebra(animalName, animalWeight, livingRegion); break; case "Cat": string breed = animalInfo[4]; animal = new Cat(animalName, animalWeight, livingRegion, breed); break; case "Tiger": animal = new Tiger(animalName, animalWeight, livingRegion); break; } string foodType = foodInfo[0]; int quantity = int.Parse(foodInfo[1]); switch (foodType) { case "Vegetable": food = new Vegetable(quantity); break; case "Meat": food = new Meat(quantity); break; } animals.Add(animal); if (animal != null && food != null) { animal.MakeSound(); animal.Eat(food); Console.WriteLine(animal.GetType().Name.ToString()); } input = Console.ReadLine(); } } } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.