COSC5910.03 Software Foundations

Instructor: J. Liu

Assignment 3. Due Tuesday April 1 in class.

Part 1

You are given an abstract class that encapsulates a stock with a stock symbol and a price. It has an abstract method, called updatePrice(). You are also provided with a class that extends the Stock class for stocks in the Toronto Stock Exchange. The abstract method updatePrice() of the Stock class is implemented in the TseStock class by extracting the price information from the Toronto Stock Exchange site.

You are to write a class, called UsStock that extends the Stock class for stocks in the United States. In order to update its stock price, we can use the URL for the New York Stock Exchange. For example, to access the quote for "IBM", we use the URL:

Similarly, to access the quote for "MSFT", we use

Use this information to implement the updatePrice() method of UsStock by extracting the latest price from this site. (Study the returned HTML document from the NYSE site to see where the last traded stock price is located. Also find out messages from the returned HTML document in case an invalid symbol is used.)

Your UsStock should also override the toString() method of Stock. For example, the string representations of the IBM and MSFT stocks should be "[U/IBM]" and "[U/MSFT]" respectively (instead of "[IBM]" and "[MSFT]").

The TseStock class serves as an example of how you might implement your UsStock. A simple tester is also provided to test your UsStock class and to illustrate the notion of polymorphism.

Part 2

This part of the assignment uses the TseStock and UsStock classes of Part 1. It is on the development of a a Java JFrame that allows the user to enter up to 10 stock symbols and the JFrame will get and display the latest stock quotes. The stock symbols can either be for TSE or for US stocks. For US stocks, the symbol entered should be preceded with "U/". For example, "BCE", "NT", "RY", "BMO" can be entered for TSE stocks; and "U/IBM", "U/MSFT", "U/AOL", "U/SUNW" should be entered for the corresponding US stocks.

You are already provided with a Java program (Run it to get familiar with its behavior). You are to write a Java code, called MyStockJFrame, that extends StockJFrame and overrides the actionPerformed(ActionEvent e) method. You may add additional static/instance variables and methods to the MyStockJFrame class the way you see appropriate.

Note that in the init() method of StockJFrame, ten text fields for stock symbols, ten display fields for stock prices and a "Refresh" button have been set up. Users can enter the selected stock symbols into the ten text fields. Either TSE or US stock symbols can be entered into any one of the text fields. In your MyStockJFrame class, whenever a symbol is entered (with a carriage return), its latest stock price should be displayed. If the stock symbol entered is invalid, the string "?????" should appear in the area for its stock price.

Any time when the "Refresh" button is pushed, all the stock prices in the MyStockJFrame should be updated by the latest quotes from the stock exchange sites.

Last Updated: 02/25/2003