Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COMSC-205 FALL 2024 ASSIGNMENT 4
Due November 18 at 11:55pm
Learning Goals
Submission Checklist
● HTMLParser.java - Reads through an HTML file, reports any errors with mismatched opening and closing tags● A README.md file that clearly states:
○ Your name and the name of the assignment○ Attribution for any sources used○ Any notes on questions, difficulties, or bugs○ If you did the challenge
● An ImpactsReflection.pdf file which contains your answers to the impacts reflection.● You do not need to submit the HTML files.
Background
What is HTML?
A markup language is used to annotate a text document with tags that describe how to format the document. Specifically, HyperText Markup Language (HTML) is the markup language usedto specify formatting for web pages and is interpreted by Internet browsers to create the display.
HTML uses tags to specify the display properties for portions of the text. For example, text can be italicized using:
<em>Hello, world!</em>
Tags are specified by using an opening tag <> and a matching closing tag </>. Between the <> in the opening tag, a command will specify what that tag means. The closing tag will have the same command following the /. You may have encountered HTML when posting text on online forums. Many will have an option to create posts using HTML (and to show what your existing post looks like in HTML). For example, in Moodle, if you click the arrow for “Show/hide advanced buttons”, then the </> “HTML” button, you can see the HTML of your post. (This can be useful if your new paragraphs don’t look like they should; <br> makes a new line, while <p> makes a new line with extra vertical space!)Comparing the simple editor to the HTML editor, you can see how different tags change the text.
<p> creates a new paragraph with extra vertical space, while <br> creates a new line. <strong> makes text bold. <em> makes text italicized. <del> draws a line through text; <u> draws a line under text. <sup> makes a superscript (letters are small and up), while <sub> makes a subscript (letters are small and down). If you want to look more in depth, you can play with it yourself in a Moodle post.
For this assignment, you must use our implementations of the MHCStackLL and MHCQueueLL classes that you did in the lab, rather than the built-in Stack and Queue classes. You can either use the ones that you created or the ones included in the starter code.
It can be tough to keep track of tags when manually writing them; Moodle has a built-in tag checker to make sure they match. This assignment asks you to create your own tag-checker.
How can a stack help with this?
Recall that a stack is a LIFO (Last-In-First-Out) data structure. We pop values in the opposite order that we push them, like a stack of plates. The last plate we put on the stack is the first plate that we remove from the stack.
How can a queue help with this?
After you are done reading the file, you can dequeue the tags one at a time, using the stack as described above to check if they match.HTML Tag-Checker
Starter code is provided that opens a file, and steps through each line of that file. The desired end result is for the program to print out a message stating whether or not the tags in the file are correctly matched. Examples of expected output are provided at the end of this document.
To build the HTML tag-checker, you need to add the following:
When running the program, the user should be able to give a filename as a command line argument. Example usage in Terminal (after java files have been compiled):
When testing your code, feel free to hard-code the filename, but make sure to change it back touse args[0] before you submit! Forget how to do command line arguments in VSCode? Check Lab 4!
Design Decisions for you to make:
● How should you handle empty tags? (Remember empty tags are tags without a closing tag, not tags missing any characters like <>)
Code-a-little / test-a-little
1. Write the code to find the tags and simply output them to the screen as you find them.
2. Write the code to push open tags and pop closing tags and check them. First, just test it on correct HTML.
3. After it works on correct HTML, try examples with different types of errors and update the code to handle those.
4. Go back to the earlier description of the rules that HTML tags follow on pages 2-3 and update your code to handle those variations of tags (tags with attributes, empty tags, mixed case tags).
Right now, your code should just print out that there is or is not an error. What if we wantedmore helpful error messages? Try changing your code so it prints how what kind of error is found: a tag mismatch (when the opening and closing tags don’t match), extra closing tag (when a closing tag exists, but there are no opening tags to match it with), or extra opening tag (when an opening tag is never closed).
Documentation and Organization
Comments are required for this and all future assignments. Make sure every method has a doc comment, and that your code is well-organized and uses good style.
Reflection on Impacts
You should submit a PDF containing 2-3 short paragraphs of reflection or separate responses to each question. Submit these on Moodle.
In your reflection, answer each of the following prompts:
● What was the most challenging part of this assignment for you? Do you feel that you understand this aspect of the assignment well now?
● Although tag checkers can help, they are not always correct. Under what circumstances does the tag checker you wrote produce false or unhelpful errors? Even if your code works on all the test files, can you think of something an html file could contain (using just the tags introduced in this assignment) that could cause it to fail?
Hints and Advice
Like we have seen on previous labs and assignments, there are built-in String methods that may be useful for your implementation. We have links to the official documentation on some of them below:
File Reading
Your program will be run with one command line argument that provides the file name of the HTML file to test, as shown in the starting code. Example files are provided with the starter code; other files will also be tested.