Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Methods Method Overloading

c-objects/methods/method-overloading/Challenge Task 3 of 3

the solution please

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;

        public Frog(int tongueLength,int reactionTime)
        {
            TongueLength = tongueLength;
            ReactionTime = reactionTime;
        }
        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;

        }
        public bool EatFly(int distanceToFly,int flyReactionTime)
        {
            bool Reaction=ReactionTime >= flyReactionTime;
            if(EatFly==true&&Reaction)
            {
                return true;
            }

        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,198 Points

You're pretty close, I bet you can get it with a few hints:

  • if the frogs reaction time is faster, the value would be less than the fly's
  • if the frog isn't able to reach the fly in time, the method should return false
  • you never need to compare a boolean value with true
  • the other form of EatFly takes the distance as a parameter

So for those last 2 items, instead of "EatFly==true" you might write "EatFly(distanceToFly)".

thank you so much it work