Skip to content

Commit 56c660f

Browse files
committedDec 30, 2015
Merge pull request #8 from rselwyn/master
Added previous close, open, and exchange.
2 parents f6b8fba + d411d70 commit 56c660f

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed
 

‎README.md

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ getMarketcap();
3131
getName();
3232
getCurrency();
3333
getShortRatio();
34+
getPreviousClose();
35+
getOpen();
36+
getExchange();
3437
```
3538

3639
## Testing

‎src/com/nhefner/main/Stock.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ public class Stock {
1616
private String name;
1717
private String currency;
1818
private double shortRatio;
19+
private double previousClose;
20+
private double open;
21+
private String exchange;
1922

2023
public Stock(String symbol, double price, int volume, double pe, double eps, double week52low,
21-
double week52high, double daylow, double dayhigh, double movingav50day, double marketcap, String name, String currency, double shortRatio) {
24+
double week52high, double daylow, double dayhigh, double movingav50day, double marketcap, String name, String currency, double shortRatio, double previousClose, double open, String exchange) {
2225
this.symbol = symbol;
2326
this.price = price;
2427
this.volume = volume;
@@ -33,7 +36,23 @@ public Stock(String symbol, double price, int volume, double pe, double eps, dou
3336
this.name = name;
3437
this.currency = currency;
3538
this.shortRatio = shortRatio;
39+
this.previousClose = previousClose;
40+
this.open = open;
41+
this.exchange = exchange;
3642
}
43+
44+
public String getExchange(){
45+
return this.exchange;
46+
}
47+
48+
public double getPreviousClose(){
49+
return this.previousClose;
50+
}
51+
52+
public double getOpen(){
53+
return this.open;
54+
}
55+
3756
public double getShortRatio(){
3857
return this.shortRatio;
3958
}

‎src/com/nhefner/main/StockFetcher.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ static Stock getStock(String symbol) {
3232
String name = "";
3333
String currency = "";
3434
double shortRatio = 0.0;
35-
35+
double open = 0.0;
36+
double previousClose = 0.0;
37+
String exchange;
3638
try {
3739

3840
// Retrieve CSV File
39-
URL yahoo = new URL("http://finance.yahoo.com/d/quotes.csv?s="+ symbol + "&f=l1vr2ejkghm3j3nc4s7");
41+
URL yahoo = new URL("http://finance.yahoo.com/d/quotes.csv?s="+ symbol + "&f=l1vr2ejkghm3j3nc4s7pox");
4042
URLConnection connection = yahoo.openConnection();
4143
InputStreamReader is = new InputStreamReader(connection.getInputStream());
4244
BufferedReader br = new BufferedReader(is);
@@ -62,14 +64,17 @@ static Stock getStock(String symbol) {
6264
name = stockinfo[10].replace("\"", "");
6365
currency = stockinfo[11].replace("\"", "");
6466
shortRatio = sh.handleDouble(stockinfo[12]);
67+
previousClose = sh.handleDouble(stockinfo[13]);
68+
open = sh.handleDouble(stockinfo[14]);
69+
exchange = stockinfo[15].replace("\"", "");
6570

6671
} catch (IOException e) {
6772
Logger log = Logger.getLogger(StockFetcher.class.getName());
6873
log.log(Level.SEVERE, e.toString(), e);
6974
return null;
7075
}
7176

72-
return new Stock(sym, price, volume, pe, eps, week52low, week52high, daylow, dayhigh, movingav50day, marketcap, name,currency, shortRatio);
77+
return new Stock(sym, price, volume, pe, eps, week52low, week52high, daylow, dayhigh, movingav50day, marketcap, name,currency, shortRatio,previousClose,open,exchange);
7378

7479
}
7580
}

‎src/com/nhefner/main/StockTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public void testStock() {
2121
System.out.println("The full name is: " + facebook.getName());
2222
System.out.println("The currency is: " + facebook.getCurrency());
2323
System.out.println("The short ratio is: " + facebook.getShortRatio());
24+
System.out.println("The previous close was: " + facebook.getPreviousClose());
25+
System.out.println("The open for today was: " + facebook.getOpen());
26+
System.out.println("The exchange is " + facebook.getExchange());
27+
2428
}
2529

2630
}

0 commit comments

Comments
 (0)