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 usingspeed
- Set the
Weight
property usingweight
- Set a random
LicensePlate
value usingTools.GenerateLicensePlate()
- Set
Wheels
to8
ifWeight
is less than 400 and setWheels
to12
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
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.