04. Wild Farm
Здравейте, извинявам се много, но може ли някой да погледне решението ми на тази задача?
Получавам 20/100 и не мога да открия къде е проблема. С третия даден инпут виждам, че имам проблем при закръглянето на weight, но в условието не е опоменато какво закръгляне да се използва. Предполагам, че не би трябвало само заради това Judge да ми дава толкова малко точки.
Благодаря предварително!
https://judge.softuni.bg/Contests/Practice/Index/1504#3 (условието е достъпно във файла)
https://github.com/elipopovadev/CSharp-OOP/tree/main/Polymorphism-Exercise/WildFarm
Hi Axiomatik ,
thanks for sharing your solution. I added some useful, but not required validation from your code in mine. And I checked my class hierarchy with yours and it's nearly the same. I find it very interesting to use enums not classes for food.![smiley smiley](https://softuni.bg/Scripts/ckeditor/plugins/smiley/images/regular_smile.png)
After checking the code in Judge it was also 20/100. I can't belive where my bug was! It was in my Feed method, I have written this:
public override void FeedIt(Food food)
{
if (!foodTypes.Any(f => f.Name == food.GetType().Name))
{
string exceptionMessages = String.Format(ExceptionMessages.InvalidFoodException, this.GetType().Name,food.GetType().Name);
throw new ArgumentException(exceptionMessages);
}
int quantity = food.Quantity;
for (int i = 0; i < quantity; i++)
{
base.Weight += IncrementIncreaseWeight;
}
base.FoodEaten += quantity;
}
but now my Feed method is without for loop:
}
100/100 https://github.com/elipopovadev/CSharp-OOP/tree/main/Polymorphism-Exercise/WildFarm
By the way you are right it's really the best choice to start with exam preparation. And I will do it mixing with exercises from High quality code course (Design patterns).
Have a nice weekend!