Skip to content

Commit

Permalink
Adding analyzer feedback for need for speed concept exercise (#2702)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
manumafe98 authored Feb 1, 2024
1 parent c93e018 commit 4dc6768
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
32 changes: 18 additions & 14 deletions exercises/concept/need-for-speed/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}

0 comments on commit 4dc6768

Please sign in to comment.