MIS 3371/Fall 2010/Final Exam/Parks/Last Name _________________________________ Last 4 PSID _______________
1. (50 points) The holiday tree shown to right is a 300x300 pixel image used as the background-image for the table cell. In the cell is a DIV block with id="tdiv". There is a button labelled "p1" that executes a javascript function named p1. There is also a textbox where the user can enter then number of ornaments to be placed on the tree. This textbox is named numo and is in a form named p1f. In the function p1 there is a seven element array named b that contains the HTML text to display seven ornament image files ( b(0)="<img src='ylball.gif' height='15'>"; b(1)="<img src='blball.gif' height='15'>";...b(6)="<img src='mgball.gif' height='15'>" ). When the user clicks the "p1" button, the function retrieves the value of numo from the textbox. The function will then use a while (condition) loop to: generate (1,2, and 3 below), test (4 below), place and count (5 below) numo ornaments (span blocks with image tags inside) into a single "output string". [Note: the "while" loop continues until the number of ornaments is equal to numo]:
  1. randomly pick an image from 0 to 6 (use: i = parseInt(Math.random() * 7.0) to find a random subscript)
  2. randomly pick a value for the Left atttribute for the ornament (use: lft=parseInt(Math.random()*285.0) to find a random left value)
  3. randomly pick a value for the Top atttribute for the ornament (use: tp=parseInt(Math.random()*285.0) to find a random top value)
  4. a function named hang is used to determine if the random lft and the random tp chosen above place the ornament on the "green" part of the background image. hang(lft,tp) returns true if the image lies on the green part of the image, otherwise false. DO NOT WRITE hang. Assume it is already written and available from p1.
    Number of ornaments       
  1. if the hang test is true for the random top and left generated above, then place the chosen image from array b in a span block that begins like this: <span style='position:absolute;top:[value of tp above];left:[value of lft above];'>. Append this SPAN block to the "output string"
  2. Then place the "output string" of span blocks with images inside in the DIV block with id="tdiv". Write the javascript for p1.
    Show NO HTML.

<xml id="census_2009">
<?xml version="1.0"?>
<!DOCTYPE census [
<!ELEMENT census (state+)>
<!ELEMENT state (state_name,county+)>
<!ELEMENT state_name (#PCDATA)>
<!ELEMENT county (county_name,population)>
<!ELEMENT county_name (#PCDATA)>
<!ELEMENT population (#PCDATA)>
]>
<census>
<state><state_name>Alabama</state_name> <county><county_name>Autauga County</county_name> <population>43671</population></county> <county><county_name>Baldwin County</county_name> <population>140415</population></county> <county><county_name>Barbour County</county_name> <population>29038</population></county> <county><county_name>Bibb County</county_name> <population>20826</population></county>
...lotsa lines omitted...
<county><county_name>Teton County</county_name> <population>18251</population></county> <county><county_name>Uinta County</county_name> <population>19742</population></county> <county><county_name>Washakie County</county_name> <population>8289</population></county> <county><county_name>Weston County</county_name> <population>6644</population></county>
</state></census></XML>
2. (50 points) The XML for the 2009 census population estimates for states and their counties are shown to the left . The DTD states that the census population estimates are arranged by states, then by county. The XML is in an IE XML container with id="census_2009". Write a javascript function named p2, that is executed by clicking this button:   This function processes the census XML to produces a page-on-the-fly with: a 51 row, 3 column table shown below that contains: (a) the state name in the first column; (b) the number of counties in the state in the second column;(c) the total state population in the third column found by summing up all the state's county populations. Further, show: (d) the total population of the census; (e) the state with the maximum population and its population; and (f) the county with the maximum population, its name, and its state. The output looks like this:

(a)(b)(c)
Alabama674447100
Alaska29610666
...lotsa states omitted...
Wisconsin725363675
Wyoming23493782
(d) Total Census Population=281401351
(e) Maximum State Population=33871648 in California
(f) Maximum County Population=9519338 in Los Angeles County in California

Notes:
root.childNodes.length is the number of states
root.childNodes(i).childNodes(0).text is the state name for state i
for (j=1;j<root.childNodes(i).childNodes.length;j++) is the loop for the counties
root.childNodes(i).childNodes(j).childNodes(0).text is the county name
root.childNodes(i).childNodes(j).childNodes(1).text is the county population

Show only the javascript for p2. Show NO HTML.