From 55fb677a2bb64ea24bac1a48a4c3f1226bc02cd5 Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Wed, 31 Jan 2024 14:45:22 -0300 Subject: [PATCH 1/2] Adding analyzer feedback for need for speed concept exercise Also as loops are not a prerequisite of the concept I made some changes to the reference resolution --- .../concept/need-for-speed/.meta/design.md | 12 ++++++++++ .../src/reference/java/NeedForSpeed.java | 22 +++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/exercises/concept/need-for-speed/.meta/design.md b/exercises/concept/need-for-speed/.meta/design.md index f99cef1f7..60755b9d2 100644 --- a/exercises/concept/need-for-speed/.meta/design.md +++ b/exercises/concept/need-for-speed/.meta/design.md @@ -17,6 +17,7 @@ - Inheritance. - Finalizers. - Method overloading. +- Loops. ## Concepts @@ -28,3 +29,14 @@ - `strings`: know how to do basic string interpolation. - `numbers`: know how to compare numbers. - `conditionals`: know how to do conditional logic. + +## 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()); } } From 50913134ad44815c1eb5f348e005e56705509fc1 Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Thu, 1 Feb 2024 17:22:34 -0300 Subject: [PATCH 2/2] Updating constructors design.md because it was a copy of another concept exercise --- .../concept/need-for-speed/.meta/design.md | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/exercises/concept/need-for-speed/.meta/design.md b/exercises/concept/need-for-speed/.meta/design.md index 60755b9d2..5cdb29564 100644 --- a/exercises/concept/need-for-speed/.meta/design.md +++ b/exercises/concept/need-for-speed/.meta/design.md @@ -2,33 +2,25 @@ ## 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. -- Loops. +- 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