Skip to content

Commit 4dc6768

Browse files
authored
Adding analyzer feedback for need for speed concept exercise (#2702)
* 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 * Updating constructors design.md because it was a copy of another concept exercise
1 parent c93e018 commit 4dc6768

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

exercises/concept/need-for-speed/.meta/design.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@
22

33
## Learning objectives
44

5-
- Know what classes are.
6-
- Know what encapsulation is.
7-
- Know what fields are.
8-
- Know how to create an object.
9-
- Know how to update state through methods.
10-
- Know about the `void` type.
5+
- Know what constructors are.
6+
- Know how to create a constructor.
7+
- Know how to initialize a new instance of a class.
8+
- Know how to differentiate them with normal methods.
119

1210
## Out of scope
1311

14-
- Reference equality.
15-
- Constructors.
16-
- Interfaces.
17-
- Inheritance.
18-
- Finalizers.
1912
- Method overloading.
13+
- No arguments constructor.
2014

2115
## Concepts
2216

23-
- `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.
17+
- `constructors`: Know how to create `constructors` and what they are.
2418

2519
## Prerequisites
2620

2721
- `basics`: know how to define a basic class with basic methods.
28-
- `strings`: know how to do basic string interpolation.
29-
- `numbers`: know how to compare numbers.
3022
- `conditionals`: know how to do conditional logic.
23+
- `classes`: know how classes work.
24+
25+
## Analyzer
26+
27+
This exercise could benefit from the following rules in the [analyzer]:
28+
29+
- `actionable`: If the student used a loop in the `tryFinishTrack()` method, encourage it to explore a different approach.
30+
31+
If the solution does not receive any of the above feedback, it must be exemplar.
32+
Leave a `celebratory` comment to celebrate the success!
33+
34+
[analyzer]: https://github.com/exercism/java-analyzer

exercises/concept/need-for-speed/.meta/src/reference/java/NeedForSpeed.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ public int distanceDriven() {
2121
return distance;
2222
}
2323

24+
public int getSpeed() {
25+
return speed;
26+
}
27+
28+
public int getBatteryDrain() {
29+
return batteryDrain;
30+
}
31+
32+
public int getCurrentBattery() {
33+
return battery;
34+
}
35+
2436
public void drive() {
2537
if (!batteryDrained()) {
2638
battery -= batteryDrain;
@@ -37,14 +49,6 @@ class RaceTrack {
3749
}
3850

3951
public boolean tryFinishTrack(NeedForSpeed car) {
40-
while (car.distanceDriven() < distance) {
41-
if (car.batteryDrained()) {
42-
return false;
43-
}
44-
45-
car.drive();
46-
}
47-
48-
return true;
52+
return ((double) distance / car.getSpeed()) <= (car.getCurrentBattery() / car.getBatteryDrain());
4953
}
5054
}

0 commit comments

Comments
 (0)