Advertisement
illpastethat

StockQuote java version

Sep 18th, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.InputStream;
  3. import java.net.URL;
  4. import java.net.URLConnection;
  5. import java.util.Scanner;
  6.  
  7. /**
  8.  * User: Adam
  9.  * Date: 9/7/12
  10.  * Time: 3:06 PM
  11.  */
  12. public class StockQuote {
  13.     public static void main(String[] args) throws IOException {
  14.         echo("Enter a stock to get the price for:");
  15.         Scanner kb = new Scanner(System.in);
  16.         String tick = kb.next();
  17.         final URL url = new URL("http://www.google.com/ig/api?stock=" + tick);
  18.         echo("trying to get the stock price for " + tick + " using " + url);
  19.         final URLConnection connection = url.openConnection();
  20.         connection.setReadTimeout(5000);
  21.         connection.setConnectTimeout(5000);
  22.         final InputStream input = connection.getInputStream();
  23.         final Scanner reader = new Scanner(input);
  24.         while (reader.hasNextLine()) {
  25.             echo("the price is somewhere below");
  26.             echo(reader.nextLine());
  27.         }
  28.     }
  29.  
  30.     private static void echo(Object o) {
  31.         System.out.println(o);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement