Monday, February 2, 2015

StockQuote.java in programe



StockQuote.java
public class StockQuote
{
            public static String readHTML(String symbol)
{
       In page = new In("http://finance.yahoo.com/q?s=" + symbol);
       String html = page.readAll();
       return html;
   }

  
   public static double price(String html)
   {
       int p     = html.indexOf("yfs_l84", 0);     
       int from  = html.indexOf(">", p);          
       int to    = html.indexOf("", from);  
       String price = html.substring(from + 1, to);
       return Double.parseDouble(price.replaceAll(",", ""));
   }

    public static String name(String html)
   {
       int p    = html.indexOf("", 0);</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>int from = html.indexOf("Summary for ", p);</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt; font-family:"Times New Roman","serif";mso-fareast-font-family:"Times New Roman"; color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>int to<span style="mso-spacerun:yes">   </span>= html.indexOf("- Yahoo! Finance", from);</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>String name = html.substring(from + 12, to);</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family: "Times New Roman","serif";mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>return name;</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">   </span>}</span><span style="font-size:14.0pt; mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family: "Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">   </span>public static String date(String html) </span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000">{</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>int p<span style="mso-spacerun:yes">    </span>= html.indexOf("<span id=\"yfs_market_time\">", 0);</span><span style="font-size: 14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>int from = html.indexOf(">", p);</span><span style="font-size:14.0pt; mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family: "Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>int to<span style="mso-spacerun:yes">   </span>= html.indexOf("-", from);<span style="mso-spacerun:yes">        </span></span><span style="font-size:14.0pt; mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family: "Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>String date = html.substring(from + 1, to);</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family: "Times New Roman","serif";mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>return date;</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">   </span>}</span><span style="font-size:14.0pt; mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family: "Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-bottom:0in;margin-bottom:.0001pt;line-height: normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-tab-count:1">            </span><span style="mso-spacerun:yes">   </span></span><span style="font-size:14.0pt;mso-bidi-font-size:10.0pt; font-family:"Times New Roman","serif";mso-fareast-font-family:"Times New Roman"; color:#C00000">public static void main(String[] args) </span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">  </span>{</span><span style="font-size:14.0pt; mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family: "Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>String symbol = args[0];</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>String html = readHTML(symbol);</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>StdOut.printf("%.2f\n", price(html));</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt; font-family:"Times New Roman","serif";mso-fareast-font-family:"Times New Roman"; color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>StdOut.println(name(html));</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">       </span>StdOut.println(date(html));</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"><span style="mso-spacerun:yes">   </span>}</span><span style="font-size:14.0pt; mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family: "Times New Roman";color:#C00000"></span></p> <p class="MsoNormal" style="margin-top:0in;margin-right:0in;margin-bottom:0in; margin-left:45.8pt;margin-bottom:.0001pt;line-height:normal;tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"> <span style="font-size:14.0pt;mso-bidi-font-size:10.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000">}</span><span style="font-size:14.0pt;mso-bidi-font-size:11.0pt;font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";color:#C00000"></span></p> <p> </p> </div>

No comments:

Post a Comment