Homework 3 (HtmlValidator) FAQ
-
Q: I don't understand HTML or web design, how am I supposed to do this assignment?
-
A: You shouldn't need to have a developed understanding of HTML to complete this assignment. All that is really necessary is knowledge of the functionality of the
HtmlTag
class that is provided to your class in the HtmlValidator
constructor and addTag
method. For a valid HTML page "... every opening tag that needs a closing tag has one and where every closing tag closes the most recently opened tag that requires a closing tag ..." the properties of each tag can be obtained using methods in the HtmlTag
class.
-
Q: I don't understand the
HtmlTag
class. Is it a string? How does my code find out information about a tag?
-
A: An
HtmlTag
is not a string; it's an object. It does contain an element that is a string, such as "p"
or "table"
. Each HtmlTag
object contains many methods for retrieving the properties of the tag. They include:
- Is it an opening/closing tag? (
isOpenTag
)
- Does it need a closing tag? (
isSelfClosing
)
- Does it match this other tag? (
matches
)
- How exactly is it written? (
toString
)
-
Q: When you say "you may use a single temporary
Stack
(in addition to your validator's own queue of tags)" what do you mean?
-
A: Your validator maintains a queue of tags, which is either initially empty or based on a set of tags passed to your constructor. In addition to this queue, you may construct a
Stack
as auxiliary storage. Construction of a Queue
or a Stack
involves use of the key word new
. This means that at any point (within any scope) in the running of your code you may have, at most (through both fields and local variables) have created one new Stack
in addition to the queue provided within the constructor (not requiring the use of new
). You may NOT use more than the specified auxiliary data structures, no additional stacks/queues, lists, arrays, or other collections.
-
Q: How does
getTags
work with my field(s)?
-
A: Your constructor maintains a queue of tags. Calls to
getTags
should return this queue. If you modify the queue tags using addTag
or removeAll
then getTags
should reflect these modifications.
-
Q: What does it mean to "... put the queue back to its original state ..."?
-
A: One of the regulations for the behavior of this class is that it should not lose track of the tags in its queue just because a method is called. For example, if the client calls
validate
, after that call, the queue should not be changed or emptied. The queue before a method call (retrieved with getTags
) should look exactly the same as the queue after the method call.
-
Q: I get the compiler error, "Cannot find symbol: method
asList
, class Arrays
". Why?
-
A: Students on Macs sometimes find that
HtmlTag.java
won't compile due to a call on Arrays.asList()
. This is probably because you still have a copy of Arrays.java
from the SortedIntList
assignment in the same directory as their HTML Validator code. Either remove Arrays.java
and Arrays.class
from the folder, or move the HTML Validator files to another folder.