Tracks
/
C#
C#
/
Exercises
/
Remote Control Competition
Remote Control Competition

Remote Control Competition

Learning Exercise

While completing Remote Control Competition, you'll learn 2 concepts

Instructions

In this exercise you will be doing some more work on remote control cars.

An experimental car has been developed and the test track needs to be adapted to handle both production and experimental models. The two types of car have already been built and you need to find a way to deal with them both on the test track.

In addition, production cars are beginning to have some success. The team boss is keen to maintain the competitive spirit by publishing a ranking of the production cars.

1. Enable cars to be driven on the same test track

Please add a method to the IRemoteControlCar interface to expose the implementations of Drive() for the two types of car.

TestTrack.Race(new ProductionRemoteControlCar());
TestTrack.Race(new ExperimentalRemoteControlCar());
// this should execute without an exception being thrown

2. Enable the distance travelled by different models on the test track to be compared

Please add a property to the IRemoteControlCar interface to expose the implementations of the DistanceTravelled property for the two types of car.

var prod = new ProductionRemoteControlCar();
TestTrack.Race(prod);
var exp = new ExperimentalRemoteControlCar();
TestTrack.Race(exp);
prod.DistanceTravelled
// => 10
exp.DistanceTravelled
// => 20

3. Allow the production cars to be ranked

Please implement the IComparable<T> interface in the ProductionRemoteControlCar class. The default sort order for cars should be ascending order of victories.

Implement the static TestTrack.GetRankedCars() to return the cars passed is sorted in ascending order of number of victories.

var prc1 = new ProductionRemoteControlCar();
var prc2 = new ProductionRemoteControlCar();
prc1.NumberOfVictories = 3;
prc2.NumberOfVictories = 2;
var rankings = TestTrack.GetRankedCars(prc1, prc2);
// => rankings[1] == prc1
Last updated 28 July 2022
Edit via GitHub The link opens in a new window or tab
C# Exercism

Ready to start Remote Control Competition?

Sign up to Exercism to learn and master C# with 62 concepts, 164 exercises, and real human mentoring, all for free.