Let's implement 3 classes with inheritance
BaseRobot
- constructor takes
name
,weight
,coords
,chipVersion
and saves them coords
should be set to 0 if not passedgoForward
,goBack
,goRight
andgoLeft
methods take astep
argument (1 by default) and move the robot bystep
in the appropriate directiongetInfo
method returns a string in the next formatRobot: %name%, Chip version: %chipVersion%, Weight: %weight%
FlyingRobot
- inherits all the methods from
BaseRobot
- takes the same args as
BaseRobot
and passes them to the parent's constructor - can work with
z
coords
- has methods
goUp
andgoDown
changingz
coordinate by a givenstep
DeliveryDrone
- inherits all the methods from
FlyingRobot
and calls its constructor - in addition to
FlyingRobot
's args it takesmaxLoadWeight
andcurrentLoad
and saves them. - has
hookLoad
method taking acargo
object and saving it to acurrentLoad
property if it is empty and thecargo.weight
is not greater than themaxLoadWeight
of the drone. - if the drone already has
currentLoad
do not change it - has
unhookLoad
method, thatcurrentLoad
property tonull
DeliveryDrone {
name: string
weight: number
chipVersion: number
maxLoadWeight: number
currentLoad: null || {
weight: number
description: string
}
coords: {
x: number
y: number
z: number
}
}
Read the guideline before start