Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.URL;
- import java.util.Scanner;
- // Copyright Albus Wulfric Percival Brian Dumbledore , 2014
- public class Check06loljk
- {
- public static void main(String[] args) throws IOException
- {
- PrintStream output = System.out;
- Scanner input = new Scanner(System.in);
- // URL (missing stock symbol) to lookup price
- final String SRC = "http://web.tmxmoney.com/quote.php?qm_symbol=";
- // Lines containing the price and time
- // Not necessarily the same if you "view source" in browser
- final int LINE_PRICE = 171;
- final int LINE_TIME = 174;
- // Get stock symbol
- output.print("Enter a stock symbol to lookup: ");
- String sym = input.next();
- Scanner fileInput = new Scanner(new URL(SRC + sym).openStream());
- // Look up information
- String price = "";
- String time = "";
- int counter = 0;
- for (int line = 1; fileInput.hasNextLine(); line++)
- {
- String code = fileInput.nextLine();
- if(line == LINE_PRICE)
- {
- code = code.toString().trim();
- price = code.replaceAll("[^0-9.]", "");
- }
- if(line == LINE_TIME)
- {
- code = code.toString().trim();
- time = code;
- }
- }
- System.out.println("The price is : "+price);
- System.out.println("At time : "+time);
- fileInput.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement