MIS 3371 SUMMER 2019 EXAM 2 PARKS ANSWERS

TOP 100 DIVIDEND STOCKS

1. (50 points) The textarea to the left contains XML for the top 100 dividend paying stocks (from here). The DTD is:
      <?xml version="1.0"?>
      <!DOCTYPE topdividendstocks[
      <!ELEMENT topdividendstocks(stock+)>
      <!ELEMENT stock (rank,stockname,tickersymbol,sector,yield)>
      <!ELEMENT rank (#PCDATA)>        [values are 1 → 100]
      <!ELEMENT stockname (#PCDATA)>
      <!ELEMENT tickersymbol(#PCDATA)>
      <!ELEMENT sector (#PCDATA)>
      <!ELEMENT yield (#PCDATA)>]       [yield is a number with a decimal point]
Assume the javascript function p1() contains:
1. the 11 possible industry sector values stored in an array named sec like this:
   var sec =["Healthcare","Real Estate","Energy","Utilities","Consumer Staples","Financial",
                  "Consumer Discretionary","Telecommunications","Industrials","Technology","Basic Materials"]
      [don't write the sec array]
2. create three eleven element arrays:
      maxyield to hold the largest yield for each sector, intialize all to 0.0
      maxname to hold the stockname of the stock with the highest yield, initialize with empty strings
      numstock to hold the number of stock in each sector, intialize with zeroes
3. assume the XML has been loaded into javascript, and that
      root.childNodes.length is the number of stocks
      root.childNodes[i].childNodes[0].childNodes[0].nodeValue is rank
      root.childNodes[i].childNodes[1].childNodes[0].nodeValue is stockname
      root.childNodes[i].childNodes[2].childNodes[0].nodeValue is tickersymbol
      root.childNodes[i].childNodes[3].childNodes[0].nodeValue is sector
      root.childNodes[i].childNodes[4].childNodes[0].nodeValue is yield
4. then create a 12 row by four column table that shows:
      a) the first row uses a predefined string named heading (Don't write heading)
      b) in the remaining 11 rows:
           in column 1, the industry sector;
           in column 2, the number of stocks in the sector;
           in column 3, the largest dividend yield for the sector;
           in column 4, the stockname with the sector's highest yield
5. place the table in the DIV block with id="p1out"
this is the DIV with id="p1out"

2. (50 points) The textarea to the left contains the 2018 largest 50 global companies by revenue (from here). The data is contained in a textarea named ta2 in a form named f2. The data for each company is:
rank
company name
industry
revenue
growth
 
employees
country
values are 1 → 50 followed by a ";"
followed by a ";"
followed by a ";"
begins with a "$" and contains one "," followed by a ";"
contains either the string "Increase" or "Decrease", followed by a number with a decimal, and ends with "%" followed by a ";"
a number that contains a comma followed by a ";"
followed by a "*" (except the last one)

Write the javascript function named p2 that:

  1. retrieves the data from ta2
  2. splits the data into companies on the "*"
  3. start an output string named os as an empty string
  4. for each company:
    • store the company's revenue value in a variable named rev
    • remove the "$" and the "," from the rev string
    • convert the string rev to an integer and divide its value by 1000.
    • create an image tag using: src='green1x1.gif', with the "height" attribute set to the value of: rev+'px'. and set the "width" attribute to "12px"
    • place the completed image tag inside a span block with: style='border-right:solid white 1px;'
    • append the result to the os string
  5. place the os string in the DIV with id="p2out"
this is the DIV with id="p2out"