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

Eslam Elewa
PLUS
Eslam Elewa
Courses Plus Student 379 Points

Why i'm still getting a Bummer! Is there a mistake i can't see ?

Why i'm still getting a Bummer! Is there a mistake i can't see ?

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

        }
    }
}

1 Answer

andren
andren
28,558 Points

There are two issues:

  1. Task 3 asks you to add another method named EatFly, it does not ask you to change the existing EatFly method. Since part of the point of this challenge is to demonstrate method overloading (which is the act of having multiple methods with the same name) changing the existing method kinda defeats the purpose.

  2. You check if the frog's reaction time is greater than or equal to the fly's reaction time. You should be checking if it is less than or equal to, since having a lesser reaction time actually means that you react to something faster.

If you fix those two issues like this:

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;
        }
    }
}

Then your code will pass.