Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.URL;
  3. import java.util.Scanner;
  4.  
  5. // Copyright Albus Wulfric Percival Brian Dumbledore , 2014
  6. public class Check06loljk
  7. {
  8.     public static void main(String[] args) throws IOException
  9.     {
  10.         PrintStream output = System.out;
  11.         Scanner input = new Scanner(System.in);
  12.        
  13.         // URL (missing stock symbol) to lookup price
  14.         final String SRC = "http://web.tmxmoney.com/quote.php?qm_symbol=";
  15.        
  16.         // Lines containing the price and time
  17.         // Not necessarily the same if you "view source" in browser
  18.         final int LINE_PRICE = 171;
  19.         final int LINE_TIME = 174;
  20.        
  21.         // Get stock symbol
  22.         output.print("Enter a stock symbol to lookup: ");
  23.         String sym = input.next();
  24.         Scanner fileInput = new Scanner(new URL(SRC + sym).openStream());
  25.        
  26.         // Look up information
  27.         String price = "";
  28.         String time = "";
  29.         int counter = 0;
  30.         for (int line = 1; fileInput.hasNextLine(); line++)
  31.         {
  32.             String code = fileInput.nextLine();
  33.         if(line == LINE_PRICE)
  34.         {
  35.             code = code.toString().trim();
  36.             price = code.replaceAll("[^0-9.]", "");
  37.         }
  38.         if(line == LINE_TIME)
  39.         {
  40.             code = code.toString().trim();
  41.             time = code;
  42.         }
  43.         }
  44.         System.out.println("The price is : "+price);
  45.         System.out.println("At time : "+time);
  46.         fileInput.close();
  47.        
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement