stockportfolio
Class StockBlock
java.lang.Object
stockportfolio.AbsStockBlock
stockportfolio.StockBlock
- All Implemented Interfaces:
- java.lang.Comparable, IStockBlock
- public class StockBlock
- extends AbsStockBlock
- implements java.lang.Comparable
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.
Constructor Summary |
StockBlock(java.lang.String stock,
java.util.Date date,
double amount,
double pricePerShare)
Create a new stock block |
Method Summary |
int |
compareTo(java.lang.Object other)
Determine the relative order of two stock blocks. |
boolean |
equals(java.lang.Object other)
Test if two stock blocks have all the same field values. |
Methods inherited from class java.lang.Object |
getClass, hashCode, notify, notifyAll, wait, wait, wait |
StockBlock
public StockBlock(java.lang.String stock,
java.util.Date date,
double amount,
double pricePerShare)
- Create a new stock block
- Parameters:
stock
- date
- amount
- pricePerShare
-
equals
public boolean equals(java.lang.Object other)
- Test if two stock blocks have all the same field values.
- Returns:
- true iff all fields of both blocks are the same.
THIS CODE SHOULD BE OK AS IS.
compareTo
public int compareTo(java.lang.Object other)
- Determine the relative order of two stock blocks.
The order sequence is : name, date, number of shares, price per share.
All ordering is ascending.
- Specified by:
compareTo
in interface java.lang.Comparable
- Parameters:
other
- any object
- Returns:
- -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:
java.lang.NullPointerException
- if the argument is null
java.lang.ClassCastException
- is the argument is not a StockBlock