From: Erik V. <eri...@hc...> - 2005-03-30 21:25:12
|
> > > In the current classes I have included: > > - in StockSpace: an ArrayList of Companies having their > markers (or tokens) > > there, > > in top-to-bottom sequence, > > - in PublicCompany: its currentPrice, which is a StockSpace > instance, > > identifying > > the location of its stock price marker (or null for > companies without priced > > shares). > > > > So the marker's StockSpace and the marked Company have a > mutual reference to > > each other. > > This is the way I would tend to approach issues like this. > > And this way we do not need a new class. > > > Ok... we should probably add accessor methods for obtaining > the location > of the marker on the stock market. Already there. You can do that from a PublicCompany object by calling getCurrentPrice(). And find the companies having markers on a specific StockSpace by calling getTokens(). In StockMarketTestServlet I draw the stock market, including the markers (just text in this case) as follows (leaving out the HTML-writing code): for (row = 0; row < stockMarket.getNumberOfRows(); row++) { for (col = 0; col < stockMarket.getNumberOfColumns(); col++) { square = stockMarket.getStockSpace(row, col); if (square != null) { /* Draw square */ iterator = square.getTokens().iterator(); while (iterator.hasNext()) { company = (PublicCompany) iterator.next(); /* Draw marker */ } } } } The getTokens() iterator returns the markers (or tokens, I see I have messed up naming seriously myself) in top-to-bottom sequence. Would you need the sequence reversed for drawing? Erik. |