创建了一个具有股票持有情况功能的 Stock 类和 Dividend Stock 类作为一个简化的实现去掉了对参数的有效性验证等细节
发布时间
阅读量:
阅读量
public class Stock {
private String symbol;
private int totalShares;
private double totalCost;
// Initializes a new Stock with no shares purchased.
public Stock(String theSymbol) {
symbol = theSymbol;
totalShares = 0;
totalCost = 0.0;
}
// Returns the total shares purchased of this stock.
public int getTotalShares() { return totalShares; }
// Returns the total profit or loss earned on this stock.
public double getProfit(double currentPrice) {
double marketValue = totalShares * currentPrice;
return marketValue - to
全部评论 (0)
还没有任何评论哟~
