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 trialJeongeui Ji
3,761 PointsCan anybody give me a hand please?
I don't understand what parameters I have to use for the constructor named reactionTime... In fact, I don't think I have gotten the question... Thanks for your help in advance.
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;
}
}
2 Answers
William Li
Courses Plus Student 26,868 Pointshi, please take a look at this line in the pre-written code template.
public readonly int TongueLength;
This is the public readonly integer field to Frog class named TougueLength.
Part 1 is essentially asking you to define another field like it only with the different name.
Hope it helps.
Maurice Abney
Courses Plus Student 9,859 PointsIt's simple when walk through the directions one step at a time
First step
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime; //Add another public readonly integer field to the Frog class named ReactionTime.
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
second step
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime; //Add another public readonly integer field to the Frog class named ReactionTime.
public Frog(int tongueLength, int reactionTime) //Add a second parameter to the constructor named reactionTime after the existing parameter
{
TongueLength = tongueLength;
ReactionTime = reactionTime; //use it to initialize the value of the ReactionTime field.
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
third step
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime; //Add another public readonly integer field to the Frog class named ReactionTime.
public Frog(int tongueLength, int reactionTime) //Add a second parameter to the constructor named reactionTime after the existing parameter
{
TongueLength = tongueLength;
ReactionTime = reactionTime; //use it to initialize the value of the ReactionTime field.
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
public bool EatFly(int distanceToFly, int flyReactionTime) //Add another method named EatFly that takes two integer parameters and returns a boolean value. Name the parameters distanceToFly and flyReactionTime.
{
if(this.TongueLength >= distanceToFly && this.ReactionTime <= flyReactionTime) //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
{
return true; //return true
}
return false;
}
}
}