Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,083 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