Learn

The car designers have asked that trucks act a bit differently from sedans. Trucks need a new property called Weight. Whenever a truck is constructed, its number of wheels will depend on its weight. For example, a heavier truck might need 12 instead of 8 wheels to support itself.

Just like sedans, trucks will also SpeedUp() and SlowDown().

Instructions

1.

Add a public double Weight property with just a getter.

2.

Add a constructor to the Truck class with two parameters: double speed and double weight. It should:

  • Set the Speed property using speed
  • Set the Weight property using weight
  • Set a random LicensePlate value using Tools.GenerateLicensePlate()
  • Set Wheels to 8 if Weight is less than 400 and set Wheels to 12 otherwise
3.

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

4.

Did you get an error? There is no setter for the Speed property. Add a private setter to that property.

5.

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?