# Purpose

The purpose of this lab is to build a program with methods as well as the other skills you have picked up over the last few weeks. Note that in this lab you will be graded on your choices of how you break the problem up into small and meaningful pieces.

Note to more advanced students: As noted above you will be graded on your choices of how you break the problem up into small and meaningful pieces. The TA's have been instructed to NOT be impressed that you found a way to code the entire lab in just three very complex lines. Please make several nice, small, natural methods.

# Requirements

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:

1. Checking accounts each with a name and an associated balance
2. Bonds each with a name, year of issue, initial value, and a rate of return
3. 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.

# Think before programming

As I have said before and will say again here, for the rest of the class you will be constantly having to think about how to break the problem into smaller pieces and to solve the pieces one at a time.

In this case you should make methods to read in the data specific to each kind of asset (stock, bond, or checking) and then compute its value. I would rather not say more that that here. This is the kind of problem you should be able to sort out now. So give it a try. If you get really stuck see a TA.

Force yourself to make small simple methods.

Again, take a look at the examples for tips on how to read web pages and files.

# Pass-off procedure

When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria:

1. Show the TA your test cases, with the input and correct output (manually written). You will be graded on the diversity of your tests. You should have about 5-10 tests. Note that you get these points for just writing the test cases, no programming required. (5 points)
2. As you start to write a program, start with small simple steps. Note that you do not have to show the TA each step individually. The TA will simply check that your program accomplishes each of these elements:
1. Prompt the user for the name of the portfolio file. The stock URL can stay the same. (5 points)
2. Scan (read) the lines of data from the portfolio file and identify each as stock, checking, bond or junk (5 points)
3. Read the data for checking accounts and accumulate these values into a grand total (5 points)
4. Read the data for bonds and accumulate these values into the grand total (5 points)
5. Read the data for stocks and accumulate these values into the grand total (5 points)
3. Is your code properly formatted (indenting blocks, comments, spacing, reasonable names of variables)? (5 points)

2 points extra credit: Most financial institutions do not compute interest in a loop. There is a formula for this. Look it up and use it. Compare the result to the loop version to assure it is right. Note that the formula depends on how often the interest is “compounded”. You will have to add another item to the bond lines for this. Also try “continuous” compounding.