/* * Created on Apr 24, 2005 */ package stockportfolio; import java.util.Date; /** Information about a single block of stock. A "block" is defined by * a number of shares of the same stock, purchased at the same time * at the same price. * * You shouldn't need change this class, if you even use it. */ public abstract class AbsStockBlock implements IStockBlock { private final String stock; private final Date date; private double amount; private final double pricePerShare; /** Create a new block of stock. * * @param stock a non-null string, which should be normalized and * used as the stock name. * @param date a non-null date, when the stock was purchased. * @param amount the number of shares purchased (must be > 0). * @param pricePerShare the price per shape (must be > 0). */ public AbsStockBlock(String stock, Date date, double amount, double pricePerShare) { this.stock = stock; //???? if (stock == null) { throw new IllegalArgumentException("stock must not be null"); } else //this.stock = stock; if (date == null) { throw new IllegalArgumentException("date must not be null"); } this.date = date; if (amount <= 0) { throw new IllegalArgumentException("amount must be positive"); } this.amount = amount; if (pricePerShare <= 0) { throw new IllegalArgumentException("price per share must not be negative"); } this.pricePerShare = pricePerShare; } /* * @see stockportfolioSolution.IStockBlock.getStock() */ public String getStock() { return this.stock; } /* * @see stockportfolioSolution.IStockBlock.getTransactionDate() */ public Date getTransactionDate() { return this.date; } /* * @see stockportfolioSolution.IStockBlock.getShares() */ public double getShares() { return this.amount; } /* * @see stocksstarter.IStockTransaction#getPricePerShare() */ public double getPricePerShare() { return this.pricePerShare; } /** Give out a one-line summary of the block information. */ public String toString() { return this.getStock() + " [" + this.getTransactionDate() + "]" + " " + this.getShares() + " shares @ " + this.getPricePerShare(); } }