Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding analyzer feedback for need for speed concept exercise #2702

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}