Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/mandarax/eca/example/StockQuote.java


1   
2   /*
3    * Copyright (C) 1998-2002 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.mandarax.eca.example;
21  
22  import java.util.Random;
23  
24  /**
25   * Class providing stock quotes for our investments. 
26   * Currently a dummy, but could be replaced by an implementation that issues HTTP requests 
27   * (peraps SOAP queries) to an online service. 
28   * @author <A HREF="mailto:j.b.dietrich@massey.ac.nz">Jens Dietrich</A>
29   */
30  public class StockQuote {
31    static Random random = new Random();
32  
33    /**
34     * Get the recent (absolute) change.
35     * @param inv an investment
36     * @return a double
37     */
38    public static double getQuote(Investment inv) {
39      double val = random.nextGaussian()*3;
40      // scale
41      val = val * inv.getValue()/100;
42      ExampleLog.LOG_EXAMPLE.debug("quote for " + inv.getSymbol() + " " + val);
43      return val;    
44    }
45    public static void main(String[] args) {
46      for (int i=0;i<20;i++) System.out.println(getQuote(null));
47    }
48  }