Create a scanner for the file and pass it to your validator

Assignment Help Computer Engineering
Reference no: EM131889482

Lab Assignment: Data Structures in Java

In this lab you will you will write a program to validate html files.

In html, tags are element names enclosed in angle brackets <>. Most tags have start and end tags which enclose some document element(s) and possibly other tags. End tags have the same name as the corresponding start tag, preceded by a '/':

<p>Arrays are <b>objects</b>, which means that when we declare an array, the<b><i>name</i></b> of the array is a <b>reference</b>
<a hef="array.jpg"></p>.

Start tags can contain attributes which provide additional information about the element, such as <imgsrc="cats.jpg">

Some tags do not surround any content. These "empty elements" have start tags but no end tags.

Restrictions for This Validator

There are multiple versions of html with different rules. We are going to simplify a bit for the purposes of this lab. We are going to use the following rules for valid html:

• tags are case insensitive

• the following tags are empty, and so have no corresponding close tag: <area>, <base>, <br>, <col>, <command>, <embed>, <hr>, <image>,<input>, <keygen>, <link>, <meta>, <param>, <source>, <track>, <wbr>

• all other tags must have a close tag

• tags must be nested correctly, so <p><b> . . .</b></p> is valid but <p><b> . . .</p></b> is not.

Input

The input is an html file which may or may not follow the restrictions described above.

Output

• each time a pair of tags is matched, print a message such as: "matched: <p> and </p>"
• each time a tag with no end tag is processed, print a message such as "no match needed: <br>"
• each time a start tag has no matching end tag, print a message such as: "missing end tag: <li>"
• each time there is no start tag to match an end tag, print a message such as "missing start tag: </head>
• if there are no errors in the file, print a message saying that the file is valid; if there are any errors in the file, print a message saying that the file is invalid

Requirements

1. Prompt for the name of the file to be validated. Create a Scanner for the file and pass it to your validator.

2. Your validator should use a stack to check for correct nesting of tags. The algorithm is similar to the algorithm for checking for balanced parentheses in our textbook. Open tags are pushed onto the stack. Each close tag is compared with the top of the stack to check for a match.

3. Don't forget that some tags have no close tag.

4. Create class for tags. This class should not have set or get methods. The Tag class should contain the list of tags with no end tag and a method to test whether a tag has no end tag. Your tag class should also have a method to test whether a pair of tags are matching start and end tags. You will probably need some additional methods in the Tag class.

5. You need to extract the tags from the input file. Attributes are not stacked. My advice is to write your own "split" method that will take a line of the input file and return an array or ArrayList of the tags (modified to remove attributes) in a line of input. A good place for this method is to make it a static method in the Tag class.

Reference no: EM131889482

Questions Cloud

What pay level does the fairness wage predict : What pay level does the fairness wage predict? Does the theory accurately predict organization behavior? Why, or why not
Discuss possible motivations for changing data structure : Discuss some possible motivations for changing the tree data structure presented in Discuss whether the change of data structure requires a change of algorithm.
Policy that allows all employees to work at home : Do you think that companies should have a policy that allows all employees to work at home? Why or why not?
What can an organizaton do to build an ethical reputation : How can managers encourage ethical behavior though his/her own actions? What can an organizaton do to build an ethical reputation?
Create a scanner for the file and pass it to your validator : Prompt for the name of the file to be validated. Create a Scanner for the file and pass it to your validator.
How does the role of hr supports the organization strategy : How is the HRM function in an organization used to support the goals of the organization?
Evaluate the recent acquisitions made by gmcr : Evaluate the recent acquisitions made by GMCR. What are the primary objectives? Apply Exhibits 6.2, 6.3, and 6.8 in framing your response here.
Brands fair trade team products : Assuming that you're in a position to afford it, would you pay the premium - the portion of the price above the price charged for non-specialty brands Fair
What is induction training : What is induction training (in Human Resource) and why is it important?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Explain the difference between cd-r and cd-rw

Assuming there are 366 days in a year, how many bits would be needed to store each day of the year? Why?

  Make a visual studio 2008 asp .net web site

make a Visual Studio 2008 ASP .NET Web Site with two Web Forms. Add a DropDownList server control and a Label server control to the first Web Form.

  Can you suggest process for choosing appropriate data-mining

Consider on how you would know if a computer were thinking like a human.

  How have the assumptions in the models changed

Recent predictions for population growth in the 21st century have changed quite a bit from predictions made. How have the assumptions in the models changed?

  Identify the independent and dependent variables

Assignment: Explain whether you chose to use an independent-samples t test or a matched-samples t test. Provide a rationale for your choice. Identify the independent and dependent variables

  Describe what a relational database is and why relational

you are the trainer for a major technology firm. one of the problems your firm has is hiring new technologists who have

  Questionsophie is development on using applocker to control

questionsophie is development on using applocker to control access to applications on a new network she has constructed

  What signal-to-noise ratio is needed

What signal-to-noise ratio is required to put a T1 carrier on a 50-kHz line.

  What combination of a and b will maximize contribution

What combination of A and B will maximize contribution, and what is the maximum possible contribution

  What is the maximum phase error allowed

If the portion of the simple-mentation margin allocated for phase errors is 0.25dB, what is the maximum phase error allowed if the target BER is 10-5?

  Prepare a multithreaded code breaking program

Prepare a  multithreaded code breaking program. You have been provided 3 files that contain text that have been  encrypted using a Caeser cypher scheme.

  Illustrate the difference between the throwing an exception

question 1 what is the difference between throwing an exception and catching an exception?question 2 how does a method

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd