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 trialAlexander V
87 PointsThis is worded so strange...
I dont even know what they want me to do
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime;
public int reactionTime(){
ReactionTime = ReactionTime;
}
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
1 Answer
Michael Davis
Courses Plus Student 12,508 PointsAdd another public readonly integer field to the Frog class named ReactionTime.
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime; // Added a new public, readonly integer named 'ReactionTime'
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
Add a second parameter to the constructor named reactionTime after the existing parameter and use it to initialize the value of the ReactionTime field.
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public readonly int ReactionTime;
// Added a 2nd parameter to the constructor named 'reactionTime'
// Initialized 'ReactionTime' to equal the parameter 'reactionTime'
public Frog(int tongueLength, int reactionTime)
{
TongueLength = tongueLength;
ReactionTime = reactionTime;
}
public bool EatFly(int distanceToFly)
{
return TongueLength >= distanceToFly;
}
}
}
Add another method named EatFly that takes two integer parameters and returns a boolean value. Name the parameters distanceToFly and flyReactionTime. 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.
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;
}
// Overloaded Method taking two parameters, `distanceToFly` and `flyReactionTime`
public bool EatFly(int distanceToFly, int flyReactionTime)
{
// If TongueLength is more than, or equal to, distance to the Fly, AND
// If the frog's ReactionTime is less than, or equal to, the flyReactionTime
// return true.
return TongueLength >= distanceToFly && ReactionTime <= flyReactionTime;
}
}
}
Adam Urteaga
19,503 PointsAdam Urteaga
19,503 PointsThank you for breaking this down. I, too, was greatly confused by the wording of the original challenge. The original wording implies there should be a constructor of name "reactionTime" instead of directing you to add a 2nd parameter named "reactionTime" to the constructor ("Frog") with existing parameter "tongueLength." Understand these are supposed to be challenging, but this seems unnecessarily obtuse.