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

dsteelz
dsteelz
1,203 Points

i don't understand the question

"Return true if the frog’s tongue is longer or equal to than the distance to the fly and its reaction time is faster or equal to than the fly’s reaction time."

I don't understand what the challenge is asking me to do. I only have one reactionTime variable. is the question asking me to compare two reactionTimes?

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)
        {
            if (TonugeLength >= distanceToFly && 
        }
    }
}

2 Answers

Mark Phillips
Mark Phillips
1,749 Points

You've added a second parameter to the constructor that sets a variable on Frog instantiation.

The question is getting you to use the second variable to check 2 predicates.

  1. how far to the fly?
  2. will the fly react before the frog?
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;
        }

// overload the EatFly method to take in the additional parameter
        public bool EatFly(int distanceToFly, int flyReactionTime)
        {
            if(TongueLength >= distanceToFly &&  ReactionTime <= flyReactionTime)
            {
                return true;
            }
            else
            { 
                return false;
            }         
        }
    }
}
dsteelz
dsteelz
1,203 Points

thanks for the assist, i see now that i misread the question. your comments/code really helped me

andren
andren
28,558 Points

There are in fact two variables containing reaction times.

There is the class property called ReactionTime which store's the frogs reaction time. And then there is flyReactionTime which is passed in to the method as a parameter and contains the fly's reaction time.

And yes you are meant to compare them to check that the frog has a faster reaction time than the fly.

dsteelz
dsteelz
1,203 Points

thanks for the clarification, the challenge makes so much sense now