RosettaCodeData/Task/Polymorphism/NetRexx/polymorphism.netrexx

105 lines
2.4 KiB
Plaintext

/* NetRexx */
options replace format comments java crossref savelog symbols binary
-- -----------------------------------------------------------------------------
class RCPolymorphism public final
method main(args = String[]) public constant
parry = [Point -
Point() -
, Point(1.0) -
, Point(1.0, 2.0) -
, Point(Point(0.3, 0.2)) -
, Circle() -
, Circle(2.0, 2.0) -
, Circle(5.0, 6.0, 7.0) -
, Circle(Point(8.0, 9.0)) -
, Circle(Point(8.0, 9.0), 4.0) -
, Circle(Circle(1.5, 1.4, 1.3)) -
]
loop pp = 0 to parry.length - 1
parry[pp].print
end pp
return
-- -----------------------------------------------------------------------------
class RCPolymorphism.Point public binary
properties private
x = double
y = double
className = Point.class.getSimpleName
method Point(x_ = double 0.0, y_ = double 0.0)
setX(x_)
setY(y_)
return
method Point(p = Point)
this(p.getX, p.getY)
return
method display public returns String
hx = '@'Rexx(Integer.toHexString(hashCode())).right(8, 0)
str = Rexx(className).left(10)':'hx': (x,y) = (' || -
Rexx(getX()).format(null, 3)',' -
Rexx(getY()).format(null, 3)')'
return str
method getX public returns double
return x
method getY public returns double
return y
method setX(x_ = double 0.0) inheritable
x = x_
return
method setY(y_ = double 0.0) inheritable
y = y_
return
method print inheritable
say display
return
-- -----------------------------------------------------------------------------
class RCPolymorphism.Circle public extends RCPolymorphism.Point binary
properties private
r = double
className = Circle.class.getSimpleName
method Circle(x_ = double 0.0, y_ = double 0.0, r_ = double 0.0)
super(x_, y_)
setR(r_)
return
method Circle(p_ = RCPolymorphism.Point, r_ = double 0.0)
this(p_.getX, p_.getY, r_)
return
method Circle(c_ = Circle)
this(c_.getX, c_.getY, c_.getR)
return
method getR public returns double
return r
method setR(r_ = double 0.0) inheritable
r = r_
return
method display public returns String
hx = '@'Rexx(Integer.toHexString(hashCode())).right(8, 0)
str = Rexx(className).left(10)':'hx': (x,y,r) = (' || -
Rexx(getX()).format(null, 3)',' -
Rexx(getY()).format(null, 3)',' -
Rexx(getR()).format(null, 3)')'
return str