exercism / java-analyzer

GNU Affero General Public License v3.0
7 stars 13 forks source link

Need for Speed - Analyzer Recommendation Feedback #184

Open klaw772 opened 2 weeks ago

klaw772 commented 2 weeks ago

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.

Norarit-Sae commented 1 week 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;
    }
Norarit-Sae commented 1 week ago

Some chose to create getSpeed() and getBattery() instead.

For example, heptalophos'solution: https://exercism.org/tracks/java/exercises/need-for-speed/solutions/heptalophos