samples/composition/src-test/org/apidesign/math/test/Factorial.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Feb 2009 17:30:06 +0100
changeset 321 06bf3a32eaa0
permissions -rw-r--r--
Moving code to org.apidesign.math package
jtulach@321
     1
package org.apidesign.math.test;
jtulach@321
     2
jtulach@321
     3
import org.apidesign.math.Arithmetica;
jtulach@321
     4
jtulach@321
     5
/** Class showing inventive, non-expected use of 
jtulach@321
     6
 * Arithmetica methods to do multiplication instead of
jtulach@321
     7
 * addition.
jtulach@321
     8
 */
jtulach@321
     9
// BEGIN: design.composition.arith.factorial
jtulach@321
    10
public final class Factorial extends Arithmetica {
jtulach@321
    11
    public static int factorial(int n) {
jtulach@321
    12
        return new Factorial().sumRange(1, n);
jtulach@321
    13
    }
jtulach@321
    14
    @Override
jtulach@321
    15
    public int sumTwo(int one, int second) {
jtulach@321
    16
        return one * second;
jtulach@321
    17
    }
jtulach@321
    18
}
jtulach@321
    19
// END: design.composition.arith.factorial
jtulach@321
    20