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

Rename tryFinishTrack to canFinishRace for better expectations #2822

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions exercises/concept/need-for-speed/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ car.distanceDriven();

## 6. Check if a remote control car can finish a race

To finish a race, a car has to be able to drive the race's distance. This means not draining its battery before having crossed the finish line. Implement the `RaceTrack.tryFinishTrack()` method that takes a `NeedForSpeed` instance as its parameter and returns `true` if the car can finish the race; otherwise, return `false`:
To finish a race, a car has to be able to drive the race's distance. This means not draining its battery before having crossed the finish line. Implement the `RaceTrack.canFinishRace()` method that takes a `NeedForSpeed` instance as its parameter and returns `true` if the car can finish the race; otherwise, return `false`:

```java
int speed = 5;
Expand All @@ -83,7 +83,7 @@ var race = new RaceTrack(distance);
car.distanceDriven()
// => 0

race.tryFinishTrack(car);
race.canFinishRace(car);
// => true

car.distanceDriven()
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/need-for-speed/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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.
- `actionable`: If the student used a loop in the `canFinishRace()` method, encourage it to explore a different approach.
- `actionable`: If the student used a conditional statement like `if/else` or ternary expressions in the `batteryDrained` method, encourage it to explore a different approach.

If the solution does not receive any of the above feedback, it must be exemplar.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RaceTrack {
this.distance = distance;
}

public boolean tryFinishTrack(NeedForSpeed car) {
public boolean canFinishRace(NeedForSpeed car) {
return ((double) distance / car.getSpeed()) <= (car.getCurrentBattery() / car.getBatteryDrain());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RaceTrack {
throw new UnsupportedOperationException("Please implement the RaceTrack constructor");
}

public boolean tryFinishTrack(NeedForSpeed car) {
throw new UnsupportedOperationException("Please implement the RaceTrack.tryFinishTrack() method");
public boolean canFinishRace(NeedForSpeed car) {
throw new UnsupportedOperationException("Please implement the RaceTrack.canFinishRace() method");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void nitro_battery_completely_drains() {

@Test
@Tag("task:6")
@DisplayName("The tryFinishCar method returns true when car can finish a race")
@DisplayName("The canFinishRace method returns true when car can finish a race")
public void car_can_finish_with_car_that_can_easily_finish() {
int speed = 10;
int batteryDrain = 2;
Expand All @@ -167,12 +167,12 @@ public void car_can_finish_with_car_that_can_easily_finish() {
int distance = 100;
var race = new RaceTrack(distance);

assertThat(race.tryFinishTrack(car)).isTrue();
assertThat(race.canFinishRace(car)).isTrue();
}

@Test
@Tag("task:6")
@DisplayName("The tryFinishCar method returns true when car can just finish a race")
@DisplayName("The canFinishRace method returns true when car can just finish a race")
public void car_can_finish_with_car_that_can_just_finish() {
int speed = 2;
int batteryDrain = 10;
Expand All @@ -181,12 +181,12 @@ public void car_can_finish_with_car_that_can_just_finish() {
int distance = 20;
var race = new RaceTrack(distance);

assertThat(race.tryFinishTrack(car)).isTrue();
assertThat(race.canFinishRace(car)).isTrue();
}

@Test
@Tag("task:6")
@DisplayName("The tryFinishCar method returns false when car just cannot finish a race")
@DisplayName("The canFinishRace method returns false when car just cannot finish a race")
public void car_can_finish_with_car_that_just_cannot_finish() {
int speed = 3;
int batteryDrain = 20;
Expand All @@ -195,12 +195,12 @@ public void car_can_finish_with_car_that_just_cannot_finish() {
int distance = 16;
var race = new RaceTrack(distance);

assertThat(race.tryFinishTrack(car)).isFalse();
assertThat(race.canFinishRace(car)).isFalse();
}

@Test
@Tag("task:6")
@DisplayName("The tryFinishCar method returns false when car cannot finish a race")
@DisplayName("The method returns false when car cannot finish a race")
gigaSproule marked this conversation as resolved.
Show resolved Hide resolved
public void car_can_finish_with_car_that_cannot_finish() {
int speed = 1;
int batteryDrain = 20;
Expand All @@ -209,7 +209,7 @@ public void car_can_finish_with_car_that_cannot_finish() {
int distance = 678;
var race = new RaceTrack(distance);

assertThat(race.tryFinishTrack(car)).isFalse();
assertThat(race.canFinishRace(car)).isFalse();
}
}