You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
// Starts the car's ignition so that it can drive.
start(): void;
// Attempt to drive a distance. Returns true or false based on whether or not the drive was successful.
drive(distance: number): boolean;
// Give the distance from the start.
getPosition(): number;
}
classCarimplementsDrivable{
private_isRunning: boolean;
private_distanceFromStart: number;
constructor(){
this._isRunning=false;
this._distanceFromStart=0;
}
/**
* Starts the car's ignition so that it can drive.
*/
publicstart(){
this._isRunning=true;
}
/**
* Attempt to drive a distance. Returns true or false based on whether or not the drive was successful.
*
* @param {number} distance The distance attempting to cover
*
* @returns {boolean} Whether or not the drive was successful
*/
publicdrive(distance: number): boolean{
if(this._isRunning){
this._distanceFromStart+=distance;
returntrue;
}
returnfalse;
}
/**
* Gives the distance from starting position
*
* @returns {number} Distance from starting position;
*/
publicgetPosition(): number{
returnthis._distanceFromStart;
}
}
// Want to experiment? Try adding a second interface: Flyable. Implement it in a Helicopter class, then write a FlyingCar class that implements both Drivable and Flyable!