Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Methods Method Overloading

Ryan Wood
Ryan Wood
888 Points

Trouble with adding a second parameter to the constructor.

The questions is this: Add a second parameter to the constructor named reactionTime after the existing parameter and use it to initialize the value of the ReactionTime field.

In the first question I constructed public readonly int ReactionTime; and in this questions I am attempting to add another parameter by doing this:

int reactionTime = ReactionTime;

Is this what is meant by adding another parameter or does this mean to add multiple parameters in a parenthesis after "public readonly int ReactionTime;

Trying to grasp what is meant here so any assistance would be greatly appreciated. I know this is probably simple but I want to be sure I have a firm understanding of what is being asked.

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

        public Frog(int tongueLength)
        {
            TongueLength = tongueLength;
        }

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


    }
}

1 Answer

Daniel Medina
Daniel Medina
13,863 Points

You have the right general idea about how to declare your ReactionTime field, but unfortunately, that is not how you add a parameter to your constructor.

You need to go to this part of your code...

public Frog(. . .)

And add this:

public Frog(int tongueLength, int reactionTime)
{
    TongueLength = tongueLength;
    ReactionTime = reactionTime;
}

I understand that constructors can be tricky, so here are a few extra links for you:

https://www.tutorialspoint.com/csharp/csharp_classes.htm https://www.dotnetperls.com/constructor

Good luck with the rest of module!

Ryan Wood
Ryan Wood
888 Points

Daniel, I was so close but thank you! I get it now. I understand a little better now after browsing your links. Those links are clutch!