Create an application that tracks investments. Let the user type a ticker symbol into a text box, enter the number of shares, and set the purchase date. A sample is shown in Figure 1-23. In the example, the price per share was obtained from a data file that was read when the application started. The combo box contains a list of investment types.
When the user selects an investment type and clicks the Confirm button, the total pur- chase amount displays in the bottom right corner of the form. See image.
A ticker symbol is a short abbreviation that uniquely identifies the name of an invest- ment such as a stock. The term ticker refers to the noise made by ticker tape machines that were once used to print stock prices.
Define a class named PriceType with two properties: Ticker (string), and Price (Double).
Define an enumerated type named InvestmentType that lists four types of investments: stock, mutual fund, commodity, and money market.
Define a class named Investment containing the following public properties:
The class should contain a shared collection of PriceType objects. Also, create a shared method in the Investment class that loads PriceType information from a comma-delim- ited text file (in real life, we would expect these values to change constantly). Each line in the text file should look like the following, in which the first value is the ticker sym- bol, and the second value is the current price:
The file should contain at least ten lines like this, each with a different ticker symbol and price.
Create a method in the Investment class that receives a ticker symbol and returns the price of the investment associated with that ticker symbol.
User Interface Notes
As the user begins to type the ticker symbol into a text box, the application should search for the symbol and display the price per share. As soon as the ticker symbol matches an existing symbol in the collection, the price should appear in a label on the form. We sug- gest that you write an event handler for the TextChanged event of the TextBox control. When the user clicks the Confirm button, its click handler should create an Investment object and initialize its properties with values in the controls on the form.