The Sedan
needs to satisfy more than the highway patrol’s rules (the IAutomobile
interface). The car designers have asked that sedans are built and move in certain ways — it must have constructors and methods that aren’t required by the IAutomobile
interface. This is okay in C#! The interface says what a class MUST have. It does not say what a class MUST NOT have.
In fact, interfaces cannot specify two types of members that are commonly found in classes:
- Constructors
- Fields
Instructions
Add a constructor to the Sedan
class with one parameter, speed
, of type double
. It should
- set the
Speed
property tospeed
- set a random
LicensePlate
value - set
Wheels
to 4
To make a random license plate, a utility class is provided for you. Use it in the constructor like so: Tools.GenerateLicensePlate()
.
Add a void SpeedUp()
method that increases the Speed
property by 5
.
Did you get an error? There is no setter for the Speed
property. Add a private setter such as private set
to the Speed
property.
Add a void SlowDown()
method that decreases the Speed
by 5
.