Closed klaw772 closed 4 months ago
I found DocInDocs's solution: https://exercism.org/tracks/java/exercises/need-for-speed/solutions/DocInDocs
They create this new function inside Class Car.
public boolean canFinishRace(int distance) {
return distance * this.batteryDrain / this.speed <= 100;
}
Some chose to create getSpeed() and getBattery() instead.
For example, heptalophos'solution: https://exercism.org/tracks/java/exercises/need-for-speed/solutions/heptalophos
I think this is a wording issue. The task is labelled Check if a remote control car can finish a race
, whereas the function name is tryFinishTrack
which are very different things. The former doesn't require the car to actually travel, whereas the latter does.
Thanks for the feedback! @gigaSproule I think you're right; maybe if the function is called checkIfCarCanFinishTheRace
or something like that instead of try, it would be even clearer. If you guys have ideas or want to open a PR to solve the issue on the java track go ahead!
@manumafe98 I've raised a PR (https://github.com/exercism/java/pull/2822), hopefully it makes sense. I made the function name match the instructions of the task.
I've also created https://github.com/exercism/java-analyzer/pull/201 for this repo.
When completing Need for Speed, the recommendation from the analyzer was as follows: "Instead of using a loop, consider returning a single expression using the <= operator. You can re-use the other methods already implemented in the class."
However, in the instructions of the exercise, the Task 6 implementation example shows that the distance driven by the car is increasing, along with the track completion being evaluated. This distance increase shown in the example seems like drive() needs to be repeatedly called using something like a loop, rather than only using a single expression to check track completion.