public class Stock {
private String store;// 股票类属性
private String symbol;// 股票代号
private String name;// 股票名称
private BigDecimal currentPrice;// 当前时间的股票价格
private BigDecimal previouClosingPrice;// 前一天的股票值
/**
* 返回前一天变到当前时间的百分比
* @return 百分比
*/
public double getChangePercent() {
return this.currentPrice.subtract(this.previouClosingPrice).abs()
.divide(this.currentPrice, 2, BigDecimal.ROUND_HALF_EVEN)
.doubleValue();
}
/**
* 返回前一天变到当前时间的百分比
* @param currentPrice 当前时间的股票价格
* @param previouClosingPrice 前一天的股票值
* @return 百分比
*/
public double getChangePercent(BigDecimal currentPrice,
BigDecimal previouClosingPrice) {
return currentPrice.subtract(previouClosingPrice).abs()
.divide(currentPrice, 2, BigDecimal.ROUND_HALF_EVEN)
.doubleValue();
}
public String getStore() {
return store;
}
public void setStore(String store) {
this.store = store;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(BigDecimal currentPrice) {
this.currentPrice = currentPrice;
}
public BigDecimal getPreviouClosingPrice() {
return previouClosingPrice;
}
public void setPreviouClosingPrice(BigDecimal previouClosingPrice) {
this.previouClosingPrice = previouClosingPrice;
}
}