51 lines
1.7 KiB
Text
51 lines
1.7 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
launchSample()
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method arithmeticMean(vv = Vector) public static signals DivideException returns Rexx
|
|
sum = 0
|
|
n_ = Rexx
|
|
loop n_ over vv
|
|
sum = sum + n_
|
|
end n_
|
|
mean = sum / vv.size()
|
|
|
|
return mean
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method launchSample() public static
|
|
TRUE_ = 1 == 1
|
|
FALSE_ = \TRUE_
|
|
tracing = FALSE_
|
|
vectors = getSampleData()
|
|
loop v_ = 0 to vectors.length - 1
|
|
say 'Average of:' vectors[v_].toString()
|
|
do
|
|
say ' =' arithmeticMean(vectors[v_])
|
|
catch dex = DivideException
|
|
say 'Caught "Divide By Zero"; bypassing...'
|
|
if tracing then dex.printStackTrace()
|
|
catch xex = RuntimeException
|
|
say 'Caught unspecified run-time exception; bypassing...'
|
|
if tracing then xex.printStackTrace()
|
|
end
|
|
say
|
|
end v_
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method getSampleData() private static returns Vector[]
|
|
seed = 1066
|
|
rng = Random(seed)
|
|
vectors =[ -
|
|
Vector(Arrays.asList([Rexx 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])), -
|
|
Vector(), -
|
|
Vector(Arrays.asList([Rexx rng.nextInt(seed), rng.nextInt(seed), rng.nextInt(seed), rng.nextInt(seed), rng.nextInt(seed), rng.nextInt(seed)])), -
|
|
Vector(Arrays.asList([Rexx rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), rng.nextDouble()])), -
|
|
Vector(Arrays.asList([Rexx '1.0', '2.0', 3.0])), -
|
|
Vector(Arrays.asList([Rexx '1.0', 'not a number', 3.0])) -
|
|
]
|
|
return vectors
|