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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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