Fixing an interface implementation

Report a typo

Following the topic of 2D simulations, imagine we have an interface of a simulated physical object, as well as an implementation of this interface in an instance of this object – in our case, a Stone.

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

interface PhysicalBody2D {
    val affectedByGravity: Boolean
        get() = true
    val simulated: Boolean
        get() = true

    val mass : Double
    val gravityStrength : Double

    val velocity : Vector2

    // You don't need to implement these functions
    fun simulate()
    fun stopSimulation()
    fun setVelocityToZero()
}

However, the interface was not implemented properly. Correct the implementation, considering that the Stone

1) Is supposed to have the mass of 0.25;

2) Is supposed to have zero velocity;

3) Is also supposed to be normally affected by gravity.

Write a program in Kotlin
// Do not change the code below.

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

interface PhysicalBody2D {
val affectedByGravity: Boolean
get() = true
val simulated: Boolean
get() = true

val mass: Double
val gravityStrength: Double

val velocity: Vector2

fun simulate()
fun stopSimulation()
fun setVelocityToZero()
}

// Do not change the code above.

/*
Physical body with a mass of 0.25,
Velocity of 0,
And no additional gravity strength
*/
class Stone : PhysicalBody2D {
override val mass: Double
get() = 0.25

override val gravityStrength: Double
get() = 1

override val velocity: Vector2

___

Create a free account to access the full topic