Classes

San Skulrattanakulchai

April 22, 2020

Topics

Objects

Object instantiation

Defining classes

Properties I

Properties II

Properties III

Properties IV

Properties V

Primary constructors I

Primary constructors II

Primary constructors III

Secondary constructors I

Secondary constructors II

Secondary constructors III

Member functions

Using classes

import kotlin.random.*
import java.awt.Color
import StdDraw.*

fun main() {
    setScale(-11.0, 11.0)
    setPenColor(BLUE)
    setPenRadius(0.01)
    val pt = Point()
    pt.show()
    repeat(100) {
        var dx = Random.nextDouble()
        if (Random.nextInt(2) == 0) dx = -dx
        var dy = Random.nextDouble()
        if (Random.nextInt(2) == 0) dy = -dy
        pt.translate(dx, dy)
        pt.show()
    }
}