Skip to content

Commit 5b59b0c

Browse files
remote-control: fix
1 parent caca361 commit 5b59b0c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

exercises/concept/remote-control-competition/.meta/Exemplar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void Drive()
1717
DistanceTravelled += 10;
1818
}
1919

20-
public int CompareTo(ProductionRemoteControlCar other)
20+
public int CompareTo(ProductionRemoteControlCar? other)
2121
{
2222
if (ReferenceEquals(this, other)) return 0;
2323
if (ReferenceEquals(null, other)) return 1;

exercises/concept/remote-control-competition/RemoteControlCompetition.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33

4-
// TODO implement the IRemoteControlCar interface
4+
public interface IRemoteControlCar
5+
{
6+
void Drive();
7+
int DistanceTravelled { get; }
8+
}
59

6-
public class ProductionRemoteControlCar
10+
public class ProductionRemoteControlCar : IRemoteControlCar, IComparable<ProductionRemoteControlCar>
711
{
812
public int DistanceTravelled { get; private set; }
913
public int NumberOfVictories { get; set; }
@@ -12,9 +16,16 @@ public void Drive()
1216
{
1317
DistanceTravelled += 10;
1418
}
19+
20+
public int CompareTo(ProductionRemoteControlCar? other)
21+
{
22+
if (ReferenceEquals(this, other)) return 0;
23+
if (ReferenceEquals(null, other)) return 1;
24+
return NumberOfVictories.CompareTo(other.NumberOfVictories);
25+
}
1526
}
1627

17-
public class ExperimentalRemoteControlCar
28+
public class ExperimentalRemoteControlCar : IRemoteControlCar
1829
{
1930
public int DistanceTravelled { get; private set; }
2031

@@ -28,12 +39,14 @@ public static class TestTrack
2839
{
2940
public static void Race(IRemoteControlCar car)
3041
{
31-
throw new NotImplementedException($"Please implement the (static) TestTrack.Race() method");
42+
car.Drive();
3243
}
3344

3445
public static List<ProductionRemoteControlCar> GetRankedCars(ProductionRemoteControlCar prc1,
3546
ProductionRemoteControlCar prc2)
3647
{
37-
throw new NotImplementedException($"Please implement the (static) TestTrack.GetRankedCars() method");
48+
var rankings = new List<ProductionRemoteControlCar> { prc1, prc2 };
49+
rankings.Sort();
50+
return rankings;
3851
}
3952
}

0 commit comments

Comments
 (0)