diff --git a/exercises/concept/need-for-speed/.meta/design.md b/exercises/concept/need-for-speed/.meta/design.md index f99cef1f7..5cdb29564 100644 --- a/exercises/concept/need-for-speed/.meta/design.md +++ b/exercises/concept/need-for-speed/.meta/design.md @@ -2,29 +2,33 @@ ## Learning objectives -- Know what classes are. -- Know what encapsulation is. -- Know what fields are. -- Know how to create an object. -- Know how to update state through methods. -- Know about the `void` type. +- Know what constructors are. +- Know how to create a constructor. +- Know how to initialize a new instance of a class. +- Know how to differentiate them with normal methods. ## Out of scope -- Reference equality. -- Constructors. -- Interfaces. -- Inheritance. -- Finalizers. - Method overloading. +- No arguments constructor. ## Concepts -- `classes`: know what classes are; know what encapsulation is; know what fields are; know how to create an object; know how to update state through methods; know about the `void` type. +- `constructors`: Know how to create `constructors` and what they are. ## Prerequisites - `basics`: know how to define a basic class with basic methods. -- `strings`: know how to do basic string interpolation. -- `numbers`: know how to compare numbers. - `conditionals`: know how to do conditional logic. +- `classes`: know how classes work. + +## Analyzer + +This exercise could benefit from the following rules in the [analyzer]: + +- `actionable`: If the student used a loop in the `tryFinishTrack()` method, encourage it to explore a different approach. + +If the solution does not receive any of the above feedback, it must be exemplar. +Leave a `celebratory` comment to celebrate the success! + +[analyzer]: https://github.com/exercism/java-analyzer diff --git a/exercises/concept/need-for-speed/.meta/src/reference/java/NeedForSpeed.java b/exercises/concept/need-for-speed/.meta/src/reference/java/NeedForSpeed.java index e3852f0dd..481e932a6 100644 --- a/exercises/concept/need-for-speed/.meta/src/reference/java/NeedForSpeed.java +++ b/exercises/concept/need-for-speed/.meta/src/reference/java/NeedForSpeed.java @@ -21,6 +21,18 @@ public int distanceDriven() { return distance; } + public int getSpeed() { + return speed; + } + + public int getBatteryDrain() { + return batteryDrain; + } + + public int getCurrentBattery() { + return battery; + } + public void drive() { if (!batteryDrained()) { battery -= batteryDrain; @@ -37,14 +49,6 @@ class RaceTrack { } public boolean tryFinishTrack(NeedForSpeed car) { - while (car.distanceDriven() < distance) { - if (car.batteryDrained()) { - return false; - } - - car.drive(); - } - - return true; + return ((double) distance / car.getSpeed()) <= (car.getCurrentBattery() / car.getBatteryDrain()); } }