/** Exists just to house static method for scraping 
  * live stock quotes from the Web. 
  * Demo idea due to Sedgewick and Wayne */
public class StockQuote{
    
    /** = current price (as String) of the stock whose
      * ticker symbol is s.
      * Precondition: s is a valid ticker symbol (case unimportant).
      * Examples: "goog", "GOOG", "MSfT" */
    //
    // Note: we'll learn how to convert to a double
    // when we learn about wrapper classes next lecture.
    public static String getQuote(String s) {
      
        // find Web data source for s
        String url= "http://finance.yahoo.com/q?s=" + s;
        
        // retrieve data as String
        // (download In.java saved to this directory; see course webpage for file)
        String data= new In(url).readAll();
        
        // pull price from String
        data= data.substring(data.indexOf("Last Trade:") + "Last Trade:".length());
        data= data.substring(0, data.indexOf("</span>"));
        data= data.substring(data.lastIndexOf(">")+1);
        
        return data; 
    }
    
    
}
