Homework 2 (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 setTags
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: How does my code find out information about a tag?
-
A: The
HtmlTag
class 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? (
requiresClosingTag
)
- Does it match this other tag? (
matches
)
- How exactly is it written? (
toString
)
-
Q: When you say "... you may use a single
Stack
and a single Queue
..." what do you mean?
-
A: You are given a queue of tags in your constructor (or later via
setTags
) and additionally you may construct a Stack
and/or a Queue
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 Queue
(LinkedList
) and one new Stack
in addition to the queue provided within the constructor or setTags
(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 do
setTags
and getTags
work with my field(s)?
-
A: Your constructor is passed a queue of tags. Calls to
getTags
(before setTags
is used) should return this queue. If you set the tags using setTags
then getTags
should return the queue that was sent to setTags
. This is so that each instance of your HtmlValidator
is not exclusive to a single collection of tags, that is, it can be re-used for another collection of tags (via setTags
) instead of having to create a new HtmlValidator
object.
-
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 may not break the queue it is given (in the constructor or
setTags
), that is, the queue (before and after method calls) must contain the exact same elements in the exact same order. The queue before a method call (retrieved with getTags
) should look exactly the same as the queue after the method call.