import java.util.Vector; // Java container class import java.util.Date; // auto generate a date, convert to String public class Order { public int ORDER_NO; // primary key public String DATE; // date as a String public Account account; // reference to parent public Stock stock; // reference to parent public String TYPE; // public visibility: same as a record struct public double PRICE; public int QTY; public static int base_order = 1000; // static var to auto generate order numbers public Order(Account account, Stock stock, String TYPE, double PRICE, int QTY) { this.account = account; this.stock = stock; this.TYPE = TYPE; this.PRICE = PRICE; this.QTY = QTY; ORDER_NO = base_order++; // auto generate Date date = new Date(); // get date/time right now DATE = date.toString(); // store as a String account.orders.addElement(this); // add itself to the parent's list of children if (TYPE.equals("SELL")) stock.sellheap.put(this); // add itself to it's parent's heap of orders else stock.buyheap.put(this); } public String toString() { return (ORDER_NO + " " + DATE + " " + account.ACCOUNT_NO + " " + stock.SYM + " " + TYPE + " " + PRICE + " " + QTY); } public void remove() { account.orders.removeElement(this); // remove itself when the QTY is consumed } }