KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lsmp > djep > xjep > function > Product


1 /* @author rich
2  * Created on 18-Nov-2003
3  *
4  * This code is covered by a Creative Commons
5  * Attribution, Non Commercial, Share Alike license
6  * <a HREF="http://creativecommons.org/licenses/by-nc-sa/1.0">License</a>
7  */

8 package org.lsmp.djep.xjep.function;
9
10 import java.util.*;
11 import org.nfunk.jep.*;
12 import org.nfunk.jep.function.*;
13
14 /**
15  * A product function product(x^2,x,1,10) finds the product of x^2 with x running from 1 to 10.
16  *
17  * @author Rich Morris
18  * Created on 10-Sept-2004
19  */

20 public class Product extends SumType {
21
22     static Multiply mul = new Multiply();
23
24     public Product()
25     {
26         super("Product");
27     }
28
29         
30     public Object JavaDoc evaluate(Object JavaDoc elements[]) throws ParseException
31     {
32         Object JavaDoc ret;
33         ret = elements[0];
34         for(int i=1;i<elements.length;++i)
35         {
36             ret = mul.mul(ret,elements[i]);
37         }
38         return ret;
39     }
40 }
41
Popular Tags