CIT597 Quiz 1
Fall, 2002

Please keep all answers short and to the point. Read each question and answer it; don't add information that wasn't asked for.

  1. If x is a double variable, write a simple assertion that x is greater than zero and less than y.
    assert x > 0 && x < y; // A single & would also work

  2. Write the same assertion as in the previous question, but this time include the values of x and y in the detail message of the AssertionError that may be thrown.
    assert x > 0 && x < y: "x = " + x + " y = " + y; // But not x + y

  3. Write the Java statement that creates a Pattern from the String "a(.*)b(.*)c(.*)d" .
    Pattern p = Pattern.compile("a(.*)b(.*)c(.*)d");
    // OK to just start with p =
  4. Write the Java statement that creates a Matcher for the String "abracadabra" using the Pattern defined in the previous question.
    Matcher m = p.matcher(p);
    // OK to just start with m =
  5. Using the above Matcher, does find() succeed? If so, what is returned by each group(N) for each legal value of N ?
    group(0) = "abracad"     group(1) = ""
    group(2) = "ra"          group(3) = "a"

  6. Write a regular expression that will succeed (using find()) on the string "abracadabra" and will return everything between the two r's in group(1).

  7. Name two elements that you should always find within an HTML <table> element.
    tr, td (or <tr>, <td>)

  8. What HTML would you write to draw a horizontal line across the page?
    <hr> (or <hr width="100%">)

  9. What HTML would you write to make the entire background of your document a bright red?
    <body bgcolor="red"> or <body bgcolor="#FF0000">
    // quotes not important in HTML

  10. Name two HTML tags that are not containers.

    <hr>, <img>, possibly others--but not <a>

  11. What attribute is required in an <img ...> tag?
    src // This is the only required tag

  12. List two (and only two) of the ways in which XHTML is stricter than HTML.
    1. Two of: tag names must be lowercase, attributes must be lowercase,
      attributes must be quoted, everything is properly nested, all attributes must have values
    2. id replaces name // incorrect but I'll accept it
  13. There are three versions of XHTML. Name two (and only two) of them.
    Two of: strict, transitional, frameset

  14. HTML and XML are designed for different purposes. Briefly, what is the purpose of each?
    1. HTML: Designed to display information to humans

    2. XML: Designed to provide data to computers

  15. What organization defines the standards for HTML, XHTML, and XML?
    World Wide Web Consortium // W3C is enough

  16. What does it mean to say that an XML document is valid?
    It conforms to a DTD // or some other kind of schema

  17. Briefly tell what each of the following symbols means in a DTD:
    1. + (plus sign) One or more

    2. * (asterisk) Zero or more

    3. ? (question mark) Optional (zero or one)

    4. | (vertical bar) Alternatives (choose one)

    5. , (comma) Things must be in the order specified

  18. Suppose an XML document consists of just a list of cartoon characters. Each character has a name and a species, for instance, Sylvester is a cat; Tweety is a bird.
    1. Write a short but complete XML document that lists these two cartoon characters. Don't forget the XML header.
      <?xml version="1.0"?>
    2. Write a DTD that describes this document. Make it general enough that we can add other cartoon characters (of other species) later. // OK to use attributes
      <!ELEMENT characters (character+)>
      <!ELEMENT character (name, species)>
      <!ELEMENT name (#PCDATA)>
      <!ELEMENT species (#PCDATA)>