Setter

class Circle(var radius: Double = 0.0) {
var area: Double
get() {
return PI * radius * radius
}
set(value) {
radius *= value
}

}
I’m meant to write a setter that increases the size of a circle. I can’t seem to access the setter.

Ignore it I misread the question.

Don’t ignore it I’m having problems creating a setter which sets the area.

Thanks in advance.

Looks like you’re setting radius wrong. How about:

//...
set(value) {
    radius = sqrt(value / PI)
}
1 Like

Doesn’t work.