Implementing an interface

Report a typo

Suppose we're now making some kind of a 2D simulation, where we have vectors and moving objects. Fix the implementation of the interface Moving and implement its functions in the YourMovingObject class.

data class Vector2(var x: Int, var y: Int)        

interface Moving {
    var currentCoordinates: Vector2

    var speed: Int

    var direction: Vector2

    // This function changes the X and Y coordinates
    // Vector2 of the object by the value equal to 
    // the multiplied speed of the object by the direction 
    // of the object plus the current coordinate.
    // (the object has the same speed along the X and Y axes).
    fun move()

    // This function reduces the speed of an object
    // along X and Y axes 
    fun slowDown(subtractedSpeed: Int)

    // This function increases the speed of an object
    // along X and Y axes 
    fun speedUp(addedSpeed: Int)

    // This function sets a new speed vector, 
    // changing the X and Y values of speed
    fun rotate(newDirection: Vector2)
}
Write a program in Kotlin
// Do not change the code below.

data class Vector2(var x: Int, var y: Int)

interface Moving {
var currentCoordinates: Vector2

var speed: Int

var direction: Vector2

// This function changes X and Y coordinates
// of an object by the amount of the object's speed
// (object has same speed along X and Y axis)
// according to direction of the object.
fun move()

// This function reduces the speed of an object
// along X and Y axes, subtracting given amount.
fun slowDown(subtractedSpeed: Int)

// This function increases the speed of an object
// along X and Y axes, adding given amount.
fun speedUp(addedSpeed: Int)

// This function sets new direction for the object,
// overwriting previous values.
fun rotate(newDirection: Vector2)
}

// Do not change the code above.

class YourMovingObject(
override var currentCoordinates: Vector2,
override var speed: Int,
override var direction: Vector2
___

Create a free account to access the full topic