Question: JAVA need help with validPage() HTML is not valid if start tags and end tags are mixed in the incorrect order. For example li>This course
JAVA need help with validPage()



HTML is not valid if start tags and end tags are mixed in the incorrect order. For example li>This course is about and their implementation in the x/b> In this case, the li end tag precedes the b tag, but since the boldface element Java language is one of the list items, /b should precede /l Your task Yor job is to complete the validPage method of the HTMLChecker class. Note that this method is passed one parameter, which is a String. The String contains HTML. The method returns true or false, depending on whether or not the String consists of valid HTML or not. Your program must do the following: 1. Identify tags. You may assume that whenever the". You may assume that the symbols and > will not appear in the String unless they start or end a tag. 2. When your program encounters a type a" or "type b" start tag, it should push the name of the tag onto a stack. For example, when it encounters the html- tag in the text above, it pushes the string "html" onto the stack (since only start tags will be placed on the stack, I suggest that you strip the> from the tag. However, for type c start tags such as cbr> (which have no corresponding end tag), the tag name should not be pushed onto the stack. 3. When your program encounters an end tag, ters an end tag, there a are several possibilities If the stack is empty, then the HTML is invalid, and the validPage method should return false immediately. Otherwise, pop the stack. If the (popped) start tag matches the end tag, then the program should continue processing the rest of the Sring. It the start tag and end tag do not match, then it depends on whether or not the start tag is "type or "type b". In the case of type a" tags, which require a corresponding end tag., your method should return false. For "type b" tags, the the stack should continue to be popped until Ci) it is empty (in which case your method should return false); or (b) until a matching start tag is found (in which case your method should continue pr a. b. c. ocessing the String) 4. If your program reaches the end of the HTML String, then it should retum true of the stack is empty or if every remaining start tag on the stack if type b
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
