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

i think i did, but i was still getting an error

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

isn't it right.?

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)
        {
            return TongueLength >= distanceToFly && ReactionTime >= flyReactionTime;
        }
    }
}

3 Answers

Kevin Agpaoa
Kevin Agpaoa
10,503 Points

Your logic is correct. I think it's an error on the TeamTreeHouse side. I tried:

return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;

and it worked. However, the logic doesn't match up with the task. Same goes for the error. "Bummer! If the frog's reaction time is greater than the fly's reaction time, the frog can't get the fly."

Hi Kevin,

You have the right logic here. A lower value means a faster reaction time.

andrewgabriel
andrewgabriel
18,106 Points

That's very strange, I just had the same problem and it worked when I changed the reaction time to be less than or equal to instead of greater than or equal to. Very odd. Thanks for the help, It was driving me crazy.

Maybe I've missed something but why is it odd if it's less than or equal to?

I think it's the correct logic. The logic originally posted in the question wasn't correct.

Supposed that the frog's reaction time is 500ms and the fly's reaction time is 600ms. This means that the frog is faster than the fly and will be able to catch it. A lower reaction time means a quicker response.

It seems to me then that we would want to make sure the frog's reaction time is less than or equal to the fly's reaction time. Otherwise, the frog won't be fast enough to catch the fly.

TongueLength >= distanceToFly && ReactionTime > flyReactionTime; now it is working.

Thanks for your response guys.