Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview: In this assignment, we will be creating an HTML Checker program that will check the syntax of HTML tags. You will write a class

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Overview: In this assignment, we will be creating an HTML Checker program that will check the syntax of HTML tags. You will write a class that stores the contents of an HTML page as a queue of HTMLTags. Your class will also be able to fix invalid HTML tags. Your HTMLManager will use stacks and queues to figure out whether the tags match and fix the mistakes it finds. There will also be a number of Instructor-provided files to help with this assignment in order to make your work a little less :-) Topics: queues, stacks Background on HTML: Web pages are written in a language called "Hypertext Markup Language", or HTML. An HTML file consists of text surrounded by markings called tags. Tags give information to the text, such as formatting (bold, italic, etc) or layout (paragraph, table, list, etc). Some tags specify comments or information about the document (header, title, document type). A tag consists of a named element between less-than symbols. For example, the tag for making text bold uses the element b and is written as b. Many tags apply to a range of text, in which case a pair of tags is used: - An opening tag (indicating the start of the range), which is written as: - A closing tag (indicating the end of the range), which is written as: tagname> So to make some text bold on a page, one would surround the text with opening and closing b tags: - HTML Code: like this - Displayed on screen: like this Tags can be nested to combine effects. For example: - HTML Code: b> like this - Displayed on screen: like this Some tags, such as the br tag (which inserts a line break) or the img (which inserts an image), do not cover a range of text and are considered to be "self-closing." Self-closing tags do not need a closing tag; for a line break, only is needed. Some web developers write self-closing tags with an optional / before the >, such as br/>. Checking HTML: One problem on the web is that many developers make mistakes in their HTML code. All tags that cover a range must eventually be closed, but some developers forget to close their tags. Also, whenever a tag is nested inside another tag, b> like this , the inner tag (i for italic, here) must be closed before the outer tag is closed. So the following tags are not valid HTML, because the should appear first: b> this is invalid This might sound like a lot if you are unfamiliar with HTML, but Don't stress! You will be provided with an algorithm for checking the validity of a series of HTML tags using stacks and queues. You will just need to follow the algorithm. Instructions Part 1: Get the starter files: For this assignment, you are provided with a number of starter files: HTMLChecker.zip - The only file that you will edit for this assignment is HTMLManager.java - The only file that you will run is HTMLChecker.java - The tests/ folder contains a few test HTML files - The expected_output/ folder contains the expected "fixed" HTML for the associated test files - these are called and compared in the HTMLChecker.java file - The other files you will mostly just ignore as they are used from the HTMLChecker, except for HTMLTag. The file HTMLTag.java you will want to study. The HTMLTag.java file: There is a provided file called HTMLTag.java which is the base type for your Queue (and the Stack that you will create in fixHTML), so it is fundamental that you know what methods it contains, though you will not edit it. An HTMLTag object corresponds to an HTML tag such as p> or table >. An HTMLTag can either be an opening tag, a closing tag, or a self-closing tag. You don't need to construct HTMLTag objects in your code, but you will process them. The reason we use HTMLTag objects instead of just storing the tags as strings is that the class provides extra functionality that makes processing HTMLTags easier. In particular, it provides the following methods: In particular, it provides the following methods: rart L: VVrite your H I IMILIManager.java tie: When developing your HTMLManager file follow the specification and algorithm below. You will know you did it correctly when you can make the HTMLChecker program run correctly. Additionally, here is a visual walk through of the fixHTML algorithm . in the correct place. - Since self-closing tags don't have to match anything, whenever you see one, you can simply add it directly back to the queue. - For opening tags, whenever you see one, you can simply add it directly back to the queue. However, you also need to keep track of if you have found it's closing tag; so, the opening tag should also be added to a Stack. [visual walk through of the - If you find a closing tag, you must determine if it is in the right place or not. In particular: - If the tag on the top of the stack matches the tag you are currently looking at, then you should add the closing tag back to the queue and remove the opening tag from the stack. (Hint: look at the difference between the equals() and the matches() method in HTMLTag) - If the tag on the top of the stack does not match the closing tag you found, then the writer of the HTML page made a mistake and we will not add that closing tag back to our queue. Instead, to fix the mistake, you should add a new closing tag that does match the opening tag at the top of the stack - and also pop the stack. (Hint: use the getMatching() method). - If you find a closing tag that has no matching open tag because the stack is empty, just discard that closing tag. - At the end of processing all the tags, if you have any left over open tags that were never closed (these would be left in the stack), you should close them. Part 3: Test your HTMLManager using HTMLChecker Run the HTMLChecker and see if your code passes all the test cases. If it does not - mine didn't on the first few tries ;-), I recommend using the debugger to - set a breakpoint on the loop inside your HTMLManager's fixHTML() - pull out your stack and queue variables from the debug panel - step through your code over and over until you figure out when things go wrong Here is an example of what your final output will look like: Processing tests/test1.html... ======================= HTML: bibr/>b i Checking HTML for errors... HTML after fix: bibr//ib Result matches Expected output! Processing tests/test2.html... ================= HTML: aaa/ Checking HTML for errors... ..-- Result matches Expected Output! All tests passed! What to Submit - Your completed HTMLManager.java - Please include at the end of this file your final output from HTMLChecker.java Submission Requirements You should do the following for_all_assignments submitted for this course. Program Comment Include a comment at the beginning of your program with the following information and a description of the program in your own words: // Your name here // CS 143 // HW Core Topics: ... // // This program will ... Program Output Include the output from a single run of your program as a block comment at the end of the program. This comment should come one blank line after the last closing curly brace in your code. 3 /8 Paste the output from JGrasp here. Altering output will earn you an automatic zero for the assignment. /

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How would we like to see ourselves?

Answered: 1 week ago