You will write a program that computes the total value of a portfolio for a pretend customer at a bank.
Your code will pull data for the portfolio from a local data file. You will prompt the user for the needed file name.
There may be three kinds of assets in the customers account:
Checking accounts each with a name and an associated balance
Bonds each with a name, year of issue, initial value, and a rate of return
Stocks each with a name and the number of shares
This will look something like this:
stock stock1 200
checking myaccount 100.00
bond mybond1 1997 100 0.07
bond mybond2 2010 1000 0.01
stock stock2 10
junk kjsdfd jkdsfj 121
"stock stock1 200" means that the pretend customer holds 200 shares of a stock called "stock1".
"checking myaccount 100.00" means that the customer has a checking account called "myaccount" containing $100.00.
"bond mybond1 1997 100 0.07" means that the customer holds a bond called "mybond1" purchased in 1997 for $100.00 that earns 7% interest per year.
Note that, as shown, the customer may have multiple (many) assets of each type. Any line that starts with something other than "stock", "checking", or "bond", including blank lines, should be ignored, for example the "junk" line shown above. Lines that start right, but lack the needed information should be ignored!.
Your program should compute the total value of the portfolio.
The value of checking accounts is just the balance given.
The value of bonds is computed assuming interest compounded annually. See pages 137 and 138 for an example. (don't include 2010)
The value of stocks is more complex to compute. For stocks you will look up the value at a web site (
http://dna.cs.byu.edu/cs142/stocks.txt ) which gives the name and share price for each stock. This "stock price data" looks like:
stock1 234.22
stock2 123.89
To compute the value of each stock you must scan through this web site (
http://dna.cs.byu.edu/cs142/stocks.txt ) , find the price and then multiply the price by the number of shares held. The TAs will check that your code looks at the website to get this information. Look at the examples for tips on how to read web pages and files. If the customer holds several stocks, you may have to scan through this file multiple times. Students that already know about arrays or other data structures will not be penalized for using them here, but do not get overly fancy.
As you did in the last labs, write some test cases. These should start very small and simple but progressively become more complex. You will use these to test that your program does what it is supposed to.