11using System ;
22using 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