Learn

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

1.

Add a constructor to the Sedan class with one parameter, speed, of type double. It should

  • set the Speed property to speed
  • 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().

2.

Add a void SpeedUp() method that increases the Speed property by 5.

3.

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.

4.

Add a void SlowDown() method that decreases the Speed by 5.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?