COB logo COB honor code logo

 

BA371 C# Assignment 1: Compound Interest Graph

 

This assignment assumes that you more or less master the various topics demonstrated and practiced in BA272 and the following BA371 labs:

Before you start this assignment, first verify these instructions for setting up the proper file structure on your ONID system (so that your instructor can harvest your work).

In this assignment, we write a (Console) program which computes the growth of a capital asset (or liability) under compound interest and different interest rates. The program writes the results to an HTML file which, when loaded into a Web browser, shows the results as a line chart (see images below).

Inputs to the program, given by the user on the console when prompted, are the following:

Here is the gist of things:

There are three important issues to consider here:
  1. How does a Web browser display data?
  2. How to compute the numbers for the graph?
  3. How to make a graph out of these numbers?
First things first, "How does a Web browser display data?"

The most common way to display data in a Web browser is to embed data in HTML 'markup' tags which instruct the browser how to display those data. For instance, to have the browser write the word "foo" in bold (as in foo), you write:

<b>foo</b>

If you enclose this whole thing in a start-HTML and end-HTML tag like so:

<html>
<b>foo</b>
</html>
and store this in a file called something like foo.html, and you pick up this file with your browser, it will place the text "foo" in bold. (try it!!)

Another way to make your browser display data is with the JavaScript programming language. If you give your browser a file with JavaScript, it will run the JavaScript code and with JavaScript code you can do things such as writing text, drawing lines, pop up windows and lots(!!) of other things.

Here is an example of a file which, when you load it into your browser, first prints foo (in bold) to the screen, then pops up a foo alert window, and when you click the alert window's OK button, prints another foo to the browser:

<html>
<b>foo</b><p/>
<script type="text/javascript">
  alert("foo");
</script>
<b>foo</b><p/>
</html>

Again, give it a try!

Now look at the code below. Notice how it is again HTML code (notice the <html> tag) containing JavaScript (ignore the line numbers).

 1 <html>
 2  <head>
 3    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
 4    <script type="text/javascript">
 5      google.load("visualization", "1", {packages:["linechart"]});
 6      google.setOnLoadCallback(drawChart);
 7      function drawChart() {
 8        var data = google.visualization.arrayToDataTable([
 9          ['Year', 'Sales', 'Expenses'],
10          ['1',  1000,      400],
11          ['2',  1170,      460],
12          ['3',  660,       1120],
13          ['4',  1030,      540]
14        ]);
15
16        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
17        chart.draw(data, {width: 1000, height: 500, legend: 'bottom', title: 'Company Performance'});
18      }
19    </script>
20  </head>
21
22  <body>
23    <div id="chart_div"></div>
24  </body>
25 </html>
Again, take this code, remove the line numbers, save it to a file foo.html, and load that file into your Web browser. Notice how it now displays a graph of some sample business data.

 

The graph is a so-called Google Line Chart (notice how the code in the script refers to Google's JavaScript API (www.google.com/jsapi).

So the challenge of this assignment is to write a program which takes some input from the user, computes information based on that input, and then writes HTML/JavaScript to a file, which, when loaded into the browser shows the compound interest chart. (PLEASE MAKE SURE THAT YOU FULLY UNDERSTAND THIS LAST SENTENCE AS IT IS THE CORE CONCEPT OF THIS ASSIGNMENT.)

Now take a good look at the chart code:

Comparing this with the compound interest example, we can infer what our program has to do:

Please study this a little, so that you develop a good sense of how the Compound Interest HTML file will resemble the above example code and how it will be different.

 

There are, as always, several ways to program this, but the following approach works well:

  1. Start with having your program collect all the input data from the user. Test this part before you go on!
  2. Have your program write the constant data in lines 1-8 to the output file.
  3. Compute the compound interest data and write those to the output file.
  4. Write example line 17 to the output file but with a different chart title.
  5. Write the remaining constant data (lines 18-25) to the output file.
  6. Once you have a working prototype, add error checking and error handling to your code.
 

Requirements

The program should exhibit the following behavior and structure:

Please Note!!

  • Some Hints
  • Please review the grading criteria