/*   
     Stock program to return the stock value given the stock symbol
     [coded by Arul John] <http://wolf.rules.it>
*/

import java.io.*;
import java.net.*;

class Stock {
    public static void main(String args[]) {
	if (args.length < 1) {
	    System.out.println("Usage: java Stock <stocksymbol>");
	    System.exit(0);
	}
	String stockSymbol = args[0];
	try {
	    URL url = new URL("http://finance.yahoo.com/q?s=" + stockSymbol);
	    DataInputStream dis = new DataInputStream(url.openStream());
	    BufferedReader buf = new BufferedReader(new InputStreamReader(dis));
	    String data;
	    data = buf.readLine();
	    String s = "<a href=\"/q?s=" + stockSymbol.toUpperCase() + "&d=t\">" + stockSymbol.toUpperCase() + "</a>";
	    boolean flag = false;
	    int initialStart = -999;
	    while (flag == false) {
		initialStart = data.indexOf(s, 0);
		if (initialStart > 0) 
		    flag = true;
		else
		    data = buf.readLine();
	    }
	    if (initialStart > 0) {
		int start = data.indexOf("<b>", initialStart);
		int end = data.indexOf("</b>", start);
		System.out.println("stock value = " + data.substring(start + 3, end));
	    }
	} catch (Exception e) {
	}
    }
}
