/* * Created on Apr 27, 2005 */ package stockportfolio; import java.util.Date; /** A concrete stock block. * * CHANGE THIS CLASS TO OVERRIDE THE compareTo method. * See JavaDoc for the Object class for information about compareTo. * See the Portfolio definition (method getBlocksOwned) to see what * the ordering between two blocks should be. * * Note: you are not required to use the AbsStockBlock provided; * it is intended as a time-saver. */ public class StockBlock extends AbsStockBlock implements Comparable { /** Create a new stock block * @param stock * @param date * @param amount * @param pricePerShare */ public StockBlock(String stock, Date date, double amount, double pricePerShare) { super(stock, date, amount, pricePerShare); } /** Test if two stock blocks have all the same field values. * @return true iff all fields of both blocks are the same. * * THIS CODE SHOULD BE OK AS IS. */ public boolean equals(Object other) { try { StockBlock block = (StockBlock) other; if (block.getStock().equals(this.getStock()) && block.getTransactionDate().equals(this.getTransactionDate()) && block.getShares() == this.getShares() && block.getPricePerShare() == this.getPricePerShare()) { return true; } } catch (ClassCastException e) { } return false; } /** Determine the relative order of two stock blocks. * The order sequence is : name, date, number of shares, price per share. * All ordering is ascending. * @param other any object * @return -1, 0, +1, as in the compareTo base method, depending on * whether the receiver is less than, equal to, or greater than the * object passed in. * @throws NullPointerException if the argument is null * @throws ClassCastException is the argument is not a StockBlock */ public int compareTo(Object other) { /* FIX ME! */ return 0; } }