MIS 3371 SPRING 2020 EXAM 2 PARKS

 

BEST 250 HUBBLE SPACE IMAGES


1. (50 points) The textarea to the left contains data on the best 250 images from the Hubble Space Telescope. The data is stored in XML using the DTD:

   <!ELEMENT hubble (image+)>
    <!ELEMENT image (id, title, width, height, src, url)>
   <!ELEMENT id (#PCDATA)>
   <!ELEMENT title (#PCDATA)>
   <!ELEMENT width (#PCDATA)>
   <!ELEMENT height (#PCDATA)>
   <!ELEMENT src (#PCDATA)>
   <!ELEMENT url (#PCDATA)>
   ]

When the button to left is clicked, a function named p1 is executed. This function:

  1. Creates a table with 250 rows by 4 column table.
    1. In column 1 place the value of id
    2. In column 2 place the value of title
    3. In column 3 place the values of width and height separated by the string " x "
    4. In column 4 place an image setting the image's src attribute to the value of src
      e.g., the first image's src is:
      https://cdn.spacetelescope.org/archives/images/thumb300y/heic1509a.jpg
  2. Create a six element array named c. Initialize the elements to zero. Assume p1 contains a string named s = "galaxy,star,planet,nebula,cluster,cosmic". As the table is being produced, count the number of times each of the six words in s occur in the 250 title values in the rows. Report the words and their counts after the table.
Show no HTML. Show only the javascript for p1

NOTES:

  • Assume a pre-written string named "headings" is avaiable for the table . Do not write the headings.
  • the number of rows in the table is: root.childNodes.length
  • the ith row's id value is: root.childNodes[i].childNodes[0].childNodes[0].nodeValue
  • the ith row's title value is: root.childNodes[i].childNodes[1].childNodes[0].nodeValue
  • the ith row's width value is: root.childNodes[i].childNodes[2].childNodes[0].nodeValue
  • the ith row's height value is: root.childNodes[i].childNodes[3].childNodes[0].nodeValue
  • the ith row's src value is: root.childNodes[i].childNodes[4].childNodes[0].nodeValue
Below is the DIV with id='p1_out' ↓

2. (50 points) The following two-dimensional array named top_10 contains real estate information about ten houses for sale.

var top_10 = [ 
 [ "jk5623", "3","2.0", "pool, detached garage",   "1344 Pine Street",    "77091", "3400", "313000", "pic0.jpg"],
 [ "rw3298", "4","4.0", "detached garage",         "3123 Apple Street",   "77112", "3209", "493000", "pic1.jpg"], 
 [ "me4596", "4","2.5", "pool, attached garage",   "5123 Oak Avenue" ,    "77141", "3100", "223000", "pic2.jpg"], 
 [ "tg6098", "4","2.5", "pool, attached garage",   "3202 Elm Street" ,    "77342", "3700", "353000", "pic3.jpg"], 
 [ "ws9821", "4","3.0", "tennis attached garage",  "1231 Birch Street",   "77154", "2900", "213000", "pic4.jpg"], 
 [ "nk6055", "4","2.5", "tennis, attached garage", "7654 Redwood Street", "77656", "4300", "273000", "pic5.jpg"], 
 [ "cd6339", "4","2.0", "detached garage",         "3322 Fir Avenue",     "77767", "3340", "323000", "pic6.jpg"], 
 [ "cd2321", "4","2.5", "attached garage",         "6479 Palm Street",    "77212", "3126", "453000", "pic7.jpg"], 
 [ "rw1134", "4","2.0", "attached garage",         "4312 Oak Avenue",     "77878", "2873", "323000", "pic8.jpg"], 
 [ "jk2011", "4","3.0", "detached garage",         "5078 Lemon Avenue",   "77323", "3045", "273000", "pic9.jpg"]
  ];
The nine columns for each real estate property are:
  1. realtor code
  2. number of bedrooms
  3. number of baths
  4. other amenities
  5. address
  6. zip code
  7. square footage (size)
  8. price ($)
  9. photo source

You are to a table with five table cells. The table has three rows. The first two rows have two table cells and the third row has only one table cell. When the button label "go" is clicked a javascript function named p2() is executed. This function p2() performs five tasks. The output of each of the five task is to be placed in one of the five table cells.

  1. in the first row first cell the program places: (1) the text "LARGEST"; (2) the realtor code of the house with the largest square footage; and (3) the photo of that house with a width of 250 pixels.
  2. in the first row second cell, the program places: (1) the text "SMALLEST"; (2) the realtor code of the house with the smallest square footage; and (3) the photo of that house with a width of 250 pixels.
  3. in the second row first cell, the program places: (1) the text "MOST EXPENSIVE"; (2)the realtor code of the house with the highest price; and (3) the photo of that house with a width of 250 pixels.
  4. in the second row second cell, the program places: (1) the text "CHEAPEST"; (2) the realtor code of the house with the lowest price; and (2) the photo of that house with a width of 250 pixels.
  5. in the third row cell, the program places: a ten row by nine column table with all columns and all rows that displays the entire top_10 array. In the last column display the image instead of its filename. Set the width of the image to 60 pixels.
Assume a pre-written heading string is available for the table named headings (do not write out this row on the exam answer). Just use it at the appropriate place in the table.

NOTES:

  • values in top_10 array are referenced by: top_10 [ i ] [ j ] (where i is the row number (0→9) and j is the column number (0→8)
TOP TEN HOMES FOR THE CLIENT

LARGEST:
realtor code
largest house image
SMALLEST:
realtor code
smallest house image
MOST EXENSIVE
realtor code
most expensive house image
CHEAPEST:
realtor code
cheapest house image
heading row
 
ten row - nine column table