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

Borislav Milev
Borislav Milev
1,218 Points

I think there is error in the question.

The error is: "If the frog's reaction time is greater than the fly's reaction time, the frog can't get the fly." I think that the frog's reaction time should be equal or greater than the fly's reaction time in order for the frog to get the fly.

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


        public bool EatFly(int distanceToFly)
        {
            return TongueLength >= distanceToFly;
        }
    }
}

1 Answer

andren
andren
28,558 Points

This is a common misunderstanding, which also confused me the first time I did the challenge. But it is correct, because "greater" and "better" are not the same thing.

If I spend 30 seconds running 100m and my opponent spends 10 seconds running 100m which ones of us has the better time? The answer is my opponent. Because in a race spending a larger number of seconds does not mean you are better.

The same is true for reaction times. If it takes 10 seconds for the frog to react to something, and it takes the fly 1 second to react to something, then the fly will react 10 times faster than the frog. A larger number is not better.

So the frog's reaction time needs to be lesser or equal to the fly's reaction time in order to react quickly enough.

As an aside It's also worth noting that the instructions specify that the EatFly method should have a distanceToFly parameter and a flyReactionTime parameter, in that order. The order matters since parameters and arguments are paired up entirely based on the order they are placed in. You have placed them in the reverse order.