Skip to content

Commit 23d0c64

Browse files
Move from constructos to need-for-speed slug (exercism#1925)
Co-authored-by: Eric Balawejder <eric.balawejder@protonmail.com>
1 parent a4f198b commit 23d0c64

11 files changed

Lines changed: 38 additions & 37 deletions

File tree

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@
105105
"status": "wip"
106106
},
107107
{
108-
"slug": "constructors",
108+
"slug": "need-for-speed",
109+
"name": "Need for Speed",
109110
"uuid": "a85b6394-3ca5-4913-b554-b460dd49c0ea",
110111
"concepts": [
111112
"constructors"
File renamed without changes.

exercises/concept/constructors/.docs/instructions.md renamed to exercises/concept/need-for-speed/.docs/instructions.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ You have six tasks, each of which will work with remote controller car instances
1212

1313
## 1. Creating a remote controlled car
1414

15-
Allow creating a remote controller car by defining a constructor for the `RemoteControlCar` class that takes the speed of the car in meters and the battery drain percentage as its two parameters (both of type `int`):
15+
Allow creating a remote controller car by defining a constructor for the `NeedForSpeed` class that takes the speed of the car in meters and the battery drain percentage as its two parameters (both of type `int`):
1616

1717
```java
1818
int speed = 5;
1919
int batteryDrain = 2;
20-
var car = new RemoteControlCar(speed, batteryDrain);
20+
var car = new NeedForSpeed(speed, batteryDrain);
2121
```
2222

2323
## 2. Creating a race track
@@ -31,12 +31,12 @@ var raceTrack = new RaceTrack(distance);
3131

3232
## 3. Drive the car
3333

34-
Implement the `RemoteControlCar.drive()` method that updates the number of meters driven based on the car's speed. Also implement the `RemoteControlCar.distanceDriven()` method to return the number of meters driven by the car:
34+
Implement the `NeedForSpeed.drive()` method that updates the number of meters driven based on the car's speed. Also implement the `NeedForSpeed.distanceDriven()` method to return the number of meters driven by the car:
3535

3636
```java
3737
int speed = 5;
3838
int batteryDrain = 2;
39-
var car = new RemoteControlCar(speed, batteryDrain);
39+
var car = new NeedForSpeed(speed, batteryDrain);
4040
car.drive();
4141

4242
car.distanceDriven();
@@ -45,12 +45,12 @@ car.distanceDriven();
4545

4646
## 4. Check for a drained battery
4747

48-
Update the `RemoteControlCar.drive()` method to drain the battery based on the car's battery drain. Also implement the `RemoteControlCar.batteryDrained()` method that indicates if the battery is drained:
48+
Update the `NeedForSpeed.drive()` method to drain the battery based on the car's battery drain. Also implement the `NeedForSpeed.batteryDrained()` method that indicates if the battery is drained:
4949

5050
```java
5151
int speed = 5;
5252
int batteryDrain = 2;
53-
var car = new RemoteControlCar(speed, batteryDrain);
53+
var car = new NeedForSpeed(speed, batteryDrain);
5454
car.drive();
5555

5656
car.batteryDrained();
@@ -59,23 +59,23 @@ car.batteryDrained();
5959

6060
## 5. Create the Nitro remote control car
6161

62-
The best-selling remote control car is the Nitro, which has a stunning top speed of 50 meters with a battery drain of 4%. Implement the (static) `RemoteControlCar.nitro()` method to return this type of car:
62+
The best-selling remote control car is the Nitro, which has a stunning top speed of 50 meters with a battery drain of 4%. Implement the (static) `NeedForSpeed.nitro()` method to return this type of car:
6363

6464
```java
65-
var car = RemoteControlCar.nitro();
65+
var car = NeedForSpeed.nitro();
6666
car.drive();
6767
car.distanceDriven();
6868
// => 50
6969
```
7070

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

73-
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 `Race.carCanFinish()` method that takes a `RemoteControlCar` instance as its parameter and returns `true` if the car can finish the race; otherwise, return `false`:
73+
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 `Race.carCanFinish()` method that takes a `NeedForSpeed` instance as its parameter and returns `true` if the car can finish the race; otherwise, return `false`:
7474

7575
```java
7676
int speed = 5;
7777
int batteryDrain = 2;
78-
var car = new RemoteControlCar(speed, batteryDrain);
78+
var car = new NeedForSpeed(speed, batteryDrain);
7979

8080
int distance = 100;
8181
var race = new Race(distance);
File renamed without changes.

exercises/concept/constructors/.meta/config.json renamed to exercises/concept/need-for-speed/.meta/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
],
66
"files": {
77
"solution": [
8-
"src/main/java/RemoteControlCar.java"
8+
"src/main/java/NeedForSpeed.java"
99
],
1010
"test": [
11-
"src/test/java/RemoteControlCarTest.java"
11+
"src/test/java/NeedForSpeedTest.java"
1212
],
1313
"exemplar": [
14-
".meta/src/reference/java/RemoteControlCar.java"
14+
".meta/src/reference/java/NeedForSpeed.java"
1515
]
1616
},
1717
"authors": [
File renamed without changes.

exercises/concept/constructors/.meta/src/reference/java/RemoteControlCar.java renamed to exercises/concept/need-for-speed/.meta/src/reference/java/NeedForSpeed.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
class RemoteControlCar {
1+
class NeedForSpeed {
22
private int speed;
33
private int batteryDrain;
44
private int distance = 0;
55
private int battery = 100;
66

7-
public RemoteControlCar(int speed, int batteryDrain) {
7+
public NeedForSpeed(int speed, int batteryDrain) {
88
this.speed = speed;
99
this.batteryDrain = batteryDrain;
1010
}
1111

12-
public static RemoteControlCar nitro() {
13-
return new RemoteControlCar(50, 4);
12+
public static NeedForSpeed nitro() {
13+
return new NeedForSpeed(50, 4);
1414
}
1515

1616
public boolean batteryDrained() {
@@ -36,7 +36,7 @@ class RaceTrack {
3636
this.distance = distance;
3737
}
3838

39-
public boolean carCanFinish(RemoteControlCar car) {
39+
public boolean carCanFinish(NeedForSpeed car) {
4040
while (!car.batteryDrained()) {
4141
car.drive();
4242
}
File renamed without changes.

exercises/concept/constructors/src/main/java/RemoteControlCar.java renamed to exercises/concept/need-for-speed/src/main/java/NeedForSpeed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class RemoteControlCar {
1+
class NeedForSpeed {
22
// TODO: define the constructor for the 'RemoteControlCar' class
33

44
public boolean batteryDrained() {
@@ -21,7 +21,7 @@ public static RemoteControlCar nitro() {
2121
class RaceTrack {
2222
// TODO: define the constructor for the 'RaceTrack' class
2323

24-
public boolean carCanFinish(RemoteControlCar car) {
24+
public boolean carCanFinish(NeedForSpeed car) {
2525
throw new UnsupportedOperationException("Please implement the RaceTrack.carCanFinish() method");
2626
}
2727
}

exercises/concept/constructors/src/test/java/RemoteControlCarTest.java renamed to exercises/concept/need-for-speed/src/test/java/NeedForSpeedTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import org.junit.Test;
44
import org.junit.Ignore;
55

6-
public class RemoteControlCarTest {
6+
public class NeedForSpeedTest {
77
@Test
88
public void new_remote_control_car_has_not_driven_any_distance() {
99
int speed = 10;
1010
int batteryDrain = 2;
11-
var car = new RemoteControlCar(speed, batteryDrain);
11+
var car = new NeedForSpeed(speed, batteryDrain);
1212

1313
assertThat(car.distanceDriven()).isEqualTo(0);
1414
}
@@ -18,7 +18,7 @@ public void new_remote_control_car_has_not_driven_any_distance() {
1818
public void drive_increases_distance_driven_with_speed() {
1919
int speed = 5;
2020
int batteryDrain = 1;
21-
var car = new RemoteControlCar(speed, batteryDrain);
21+
var car = new NeedForSpeed(speed, batteryDrain);
2222

2323
car.drive();
2424

@@ -30,7 +30,7 @@ public void drive_increases_distance_driven_with_speed() {
3030
public void drive_does_not_increase_distance_driven_when_battery_drained() {
3131
int speed = 9;
3232
int batteryDrain = 50;
33-
var car = new RemoteControlCar(speed, batteryDrain);
33+
var car = new NeedForSpeed(speed, batteryDrain);
3434

3535
// Drain the battery
3636
car.drive();
@@ -47,7 +47,7 @@ public void drive_does_not_increase_distance_driven_when_battery_drained() {
4747
public void new_remote_control_car_battery_is_not_drained() {
4848
int speed = 15;
4949
int batteryDrain = 3;
50-
var car = new RemoteControlCar(speed, batteryDrain);
50+
var car = new NeedForSpeed(speed, batteryDrain);
5151

5252
assertThat(car.batteryDrained()).isFalse();
5353
}
@@ -57,7 +57,7 @@ public void new_remote_control_car_battery_is_not_drained() {
5757
public void drive_to_almost_drain_battery() {
5858
int speed = 2;
5959
int batteryDrain = 1;
60-
var car = new RemoteControlCar(speed, batteryDrain);
60+
var car = new NeedForSpeed(speed, batteryDrain);
6161

6262
// Almost drain the battery
6363
for (var i = 0; i < 99; i++) {
@@ -72,7 +72,7 @@ public void drive_to_almost_drain_battery() {
7272
public void drive_until_battery_is_drained() {
7373
int speed = 2;
7474
int batteryDrain = 1;
75-
var car = new RemoteControlCar(speed, batteryDrain);
75+
var car = new NeedForSpeed(speed, batteryDrain);
7676

7777
// Drain the battery
7878
for (var i = 0; i < 100; i++) {
@@ -85,29 +85,29 @@ public void drive_until_battery_is_drained() {
8585
@Ignore("Remove to run test")
8686
@Test
8787
public void nitro_car_has_not_driven_any_distance() {
88-
var car = RemoteControlCar.nitro();
88+
var car = NeedForSpeed.nitro();
8989
assertThat(car.distanceDriven()).isEqualTo(0);
9090
}
9191

9292
@Ignore("Remove to run test")
9393
@Test
9494
public void nitro_car_has_battery_not_drained() {
95-
var car = RemoteControlCar.nitro();
95+
var car = NeedForSpeed.nitro();
9696
assertThat(car.batteryDrained()).isFalse();
9797
}
9898

9999
@Ignore("Remove to run test")
100100
@Test
101101
public void nitro_car_has_correct_speed() {
102-
var car = RemoteControlCar.nitro();
102+
var car = NeedForSpeed.nitro();
103103
car.drive();
104104
assertThat(car.distanceDriven()).isEqualTo(50);
105105
}
106106

107107
@Ignore("Remove to run test")
108108
@Test
109109
public void nitro_has_correct_battery_drain() {
110-
var car = RemoteControlCar.nitro();
110+
var car = NeedForSpeed.nitro();
111111

112112
// The battery is almost drained
113113
for (var i = 0; i < 24; i++) {
@@ -126,7 +126,7 @@ public void nitro_has_correct_battery_drain() {
126126
public void car_can_finish_with_car_that_can_easily_finish() {
127127
int speed = 10;
128128
int batteryDrain = 2;
129-
var car = new RemoteControlCar(speed, batteryDrain);
129+
var car = new NeedForSpeed(speed, batteryDrain);
130130

131131
int distance = 100;
132132
var race = new RaceTrack(distance);
@@ -139,7 +139,7 @@ public void car_can_finish_with_car_that_can_easily_finish() {
139139
public void car_can_finish_with_car_that_can_just_finish() {
140140
int speed = 2;
141141
int batteryDrain = 10;
142-
var car = new RemoteControlCar(speed, batteryDrain);
142+
var car = new NeedForSpeed(speed, batteryDrain);
143143

144144
int distance = 20;
145145
var race = new RaceTrack(distance);
@@ -152,7 +152,7 @@ public void car_can_finish_with_car_that_can_just_finish() {
152152
public void car_can_finish_with_car_that_just_cannot_finish() {
153153
int speed = 3;
154154
int batteryDrain = 20;
155-
var car = new RemoteControlCar(speed, batteryDrain);
155+
var car = new NeedForSpeed(speed, batteryDrain);
156156

157157
int distance = 16;
158158
var race = new RaceTrack(distance);
@@ -165,7 +165,7 @@ public void car_can_finish_with_car_that_just_cannot_finish() {
165165
public void car_can_finish_with_car_that_cannot_finish() {
166166
int speed = 1;
167167
int batteryDrain = 20;
168-
var car = new RemoteControlCar(speed, batteryDrain);
168+
var car = new NeedForSpeed(speed, batteryDrain);
169169

170170
int distance = 678;
171171
var race = new RaceTrack(distance);

0 commit comments

Comments
 (0)