home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / LocalQuote.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.0 KB  |  43 lines

  1.  
  2. package sunw.demo.quote;
  3.  
  4. import java.util.Vector;
  5. import java.util.Date;
  6. import java.util.Hashtable;
  7.  
  8.  
  9. /**
  10.  * Produces random stock quotes.  Useful for demos where
  11.  * and internet connection isn't available or the market
  12.  * has closed.
  13.  *
  14.  * @see sunw.demo.quote.YahooQuote 
  15.  */
  16.  
  17. public class LocalQuote
  18. {
  19.   static private final double dx = Math.PI / 8;
  20.   static private int x = 0;
  21.  
  22.   static Hashtable getQuotes(QuoteServer server, Vector symbols)
  23.   {
  24.     Hashtable rv = new Hashtable();
  25.     for(int i = 0; i < symbols.size(); i++) {
  26.       String symbol = ((String)symbols.elementAt(i)).toUpperCase();
  27.       int iprice = (int)((50.0 * Math.random()) + (10.0 * (1.0 + Math.sin(x++ * dx))));
  28.       double price = iprice + ((int)(Math.random() * 8.0) * 0.125);
  29.       double bid = 0.9 * price;
  30.       double ask = 1.1 * price;
  31.       double open = 25.0;
  32.       long volume = x * 100000;
  33.       Date date = new Date();
  34.       QuoteEvent event = new QuoteEvent(server, symbol, date, price, bid, ask, open, volume);
  35.       rv.put(symbol, event);
  36.     }
  37.     
  38.     return rv;
  39.   }
  40. }
  41.  
  42.  
  43.