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

Adding second parameter

I'm trying to add a second parameter to the code but the method i keep on trying doesn't work and keeps returning the error message--- Bummer! Your code could not be compiled. Please click on "Preview" to view the compiler errors---

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;

        public Frog(int tongueLength)

        {
            TongueLength = tongueLength;
        }

        public bool EatFly(int distanceToFly)

        {
            return TongueLength >= distanceToFly;
        }

        public readonly int ReactionTime;

        {
            ReactionTime = reactionTime;
        }

    }

}

1 Answer

Hendrik Heim
Hendrik Heim
1,012 Points

Hey Paul!

The task is to create another boolean Method "EatFly" with two Parameters as shown below.

You had some errors below your ReactionTime field and I don't get your intention there.

Anyways, here is the solution:

class Frog
    {
        public readonly int TongueLength;
        public readonly int ReactionTime;
        public Frog(int tongueLength)

        {
            TongueLength = tongueLength;
        }

        public bool EatFly(int distanceToFly)

        {
            return TongueLength >= distanceToFly;
        }

        public bool EatFly(int distanceToFly, int flyReactionTime){

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

    }