{ "key_pair_value_system": true, "answer_rating_count": "", "question_feedback_html": { "html_star": "", "html_star_feedback": "" }, "answer_average_rating_value": "", "answer_date_js": "2024-09-26T00:05:16-04:00", "answer_date": "2024-09-26 00:05:16", "is_docs_available": "", "is_excel_available": "", "is_pdf_available": "", "count_file_available": 0, "main_page": "student_question_view", "question_id": "13563190", "url": "\/study-help\/questions\/java-your-task-is-to-write-a-class-called-htmlchecker-13563190", "question_creation_date_js": "2024-09-26T00:05:16-04:00", "question_creation_date": "Sep 26, 2024 12:05 AM", "meta_title": "[Solved] JAVA. Your task is to write a class calle | SolutionInn", "meta_description": "Answer of - JAVA. Your task is to write a class called HTMLChecker. As you may be aware, many resources of the World Wide Web are | SolutionInn", "meta_keywords": "java,task,write,class,called,htmlchecker,aware,resources,world,wide,web,written", "question_title_h1": "JAVA. Your task is to write a class called HTMLChecker. As you may be aware, many resources of the World Wide Web are written in", "question_title": "JAVA. Your task is to write a class called HTMLChecker. As you", "question_title_for_js_snippet": "JAVA Your task is to write a class called HTMLChecker As you may be aware, many resources of the World Wide Web are written in a markup language called HTML (Hypertext Markup Language) You do not need to know the details of HTML to complete this assignment All you need to know is the following 1 HTML files consist of tags and text A tag is enclosed in Tags determine how the text is formatted when a Web page is viewed by someone using a Web browser 2 There are 2 types of tags start tags and end tags An end tag has a forward slash ( ) immediately after the symbol 3 Here are some examples of tags display text that follows in the form of an ordered list (i e , bullet points that are numbered) The corresponding end tag is , which indicates the end of the ordered list display text that follows as an unordered list Instead of numbering the items in the list, bullet points are used The corresponding end tag is The text that follows is a list item, either in an ordered list or an unordered list Although there is a corresponding end tag exists, the use of this end tag is optional, as discussed below Insert a paragraph break It has an optional end tag Place the text that follows on a new line There is no corresponding end tag Display text in boldface is the end tag , , and Display text in different font sizes is the largest font, followed by and All are larger than the normal font that a particular Web page uses The end tags are as you would expect ( , etc ) 4 There are 3 types of start tags, which I will refer to as types a, b, and c For start tags of type a, it is a requirement of HTML that a corresponding end tag must follow at some point in the HTML file For example, an ordered list begins with the start tag and must end with the end tag 5 For type b start tags, the corresponding end tag is optional The and the tags are examples tags for which the corresponding end tag is optional may or may not be followed by (and likewise, may or may not be followed by ) 6 For type c start tags, there is no corresponding end tag is an example of such a tag there is no tag in HTML On the following page, you will find an example of valid HTML, and the way it is rendered by a browser Note the following a Spacing is determined strictly by tags, and by the size of the browser window For example, in the first list item there is a line break between implementation in and the Java language because of the browser window size On the other hand, even though the text Java and language in the html file are on separate lines, no line break appears at that point in the IE rendering of the page Finally, the Web browser has place a paragraph break between at the following times and Section 201 students because of the tag, and not due to any formatting of the text in the html file b HTML elements (which consist of a start tag, text, and in most cases an end tag) may be embedded within other elements In the above HTML, there are several instance of appearing within other elements, as in This course is about data structures and their implementation in the Java language CSC 300 Section 201, 210 Summer I 2017 This course is about data structures and their implementation in the Java language We will discuss Bags, Stacks, Queues, Lists, and Priority Queues In addition, we will discuss the running times of various operations on different data structures The class meets at the following times Sections 201 students Tuesdays and Thursdays from 5 45 9 00 Section 210 students Online students view the lectures on D2L HTML is not valid if start tags and end tags are mixed in the incorrect order For example This course is about data structures and their implementation in the Java language In this case, the end tag precedes the tag, but since the boldface element Java language is one of the list items, should precede Your task Your 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 symbol appears, it begins a tag (of course, end tags begin with 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 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 (which have no corresponding end tag), the tag name should not be pushed onto the stack 3 When your program encounters an end tag, there are several possibilities a If the stack is empty, then the HTML is invalid, and the validPage method should return false immediately b Otherwise, pop thes stack If the (popped) start tag matches the end tag, then the program should continue processing the rest of the String c It the start tag and end tag do not match, then it depends on whether or not the start tag is type a 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 (i) 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 processing the String) 4 If your program reaches the end of the HTML String, then it should return true of the stack is empty or if every remaining start tag on the stack if type b Here is an example of how your validPage should work on a small subset of the example HTML above Assume the String passed as a parameter to validPage is all on a single line HTMLChecker validPage( CSC 300 This course is about data structures and their implementation in the Java language We will discuss Bags, Stacks, Queues, Lists, and Priority Queues In addition, we will discuss the running times of various operations on different data structures ) Tag Stack Tag Stack center p ol li center h3 p ol li b center h3 b ol li center h3 ol li p center ol li p li ol p p ol p Note that when the tag is encountered (marked by ), several items are popped from the stack, since they are all type b start tags, which do not require end tags If any of them were type a tags, at this point the validPage method would return false For this html String, in the end your validPage method should return true This is valid HTML, because the only tag left on the stack ( ) is a type b tag, for which a is optional Code I am providing If you download the hw3 jar file, you will see a partially completed version of the validHTML method which you must complete Here is a portion of the code I am providing The intent of the starter code is to relieve you of the burden of writing the string manipulation part of the validHTML method (mainly, identifying and extracting tags, and determining if they are start or end tags), so that you can concentrate on the correct manipulation of the stack public static boolean validPage(String html) the stack that we'll use to save start tags for which we are (possibly) expecting a corresponding end tag Whether the end tag is required or optional depends on the type of the start tag ( type a or type b ) Stack startTags new Stack () find the index of the first start tag in html (the parameter String) int tagStartPosition html indexOf(' ', tagStartPosition 1) if (tagEndPosition 1) return false extract the tag String tag html substring(tagStartPosition 1, tagEndPosition) determine if the tag is a start tag or and end tag if (tag charAt(0) ' ') tag tag substring(1) isStartTag false else isStartTag true fill in the rest of the code here tagStartPosition html indexOf('", "question_description": "
JAVA.<\/p>
Your task is to write a class called HTMLChecker. As you may be aware, many resources of the World Wide Web are written in a markup language called HTML (Hypertext Markup Language). You do not need to know the details of HTML to complete this assignment. All you need to know is the following:<\/p>
1. HTML files consist of tags and text. A tag is enclosed in < ... >. Tags determine how the text is formatted when a Web page is viewed by someone using a Web browser.<\/p>
2. There are 2 types of tags; start tags and end tags. An end tag has a forward slash (\/) immediately after the < symbol.<\/p>
3. Here are some examples of tags:<\/p>
: Insert a paragraph break. It has an optional end tag <\/p>. : Place the text that follows on a new line. There is no corresponding <\/br> end<\/p>
tag. : Display text in boldface. <\/b> is the end tag.<\/p>
4. There are 3 types of start tags, which I will refer to as types a, b, and c. For start tags of type a, it is a requirement of HTML that a corresponding end tag must follow at some point in the HTML file. For example, an ordered list begins with the
5. For type b start tags, the corresponding end tag is optional. The
and the
may or may not be followed by <\/p> (and likewise,
6. For type c start tags, there is no corresponding end tag. is an example of such a tag; there is no <\/br> tag in HTML.<\/p>
On the following page, you will find an example of valid HTML, and the way it is rendered by a browser. Note the following:<\/p>
a. Spacing is determined strictly by tags, and by the size of the browser window. For example, in the first list item there is a line break between implementation in and the Java language because of the browser window size. On the other hand, even though the text Java and language in the .html file are on separate lines, no line break appears at that point in the IE rendering of the page. Finally, the Web browser has place a paragraph break between at the following times: and Section 201 students because of the
tag, and not due to any formatting of the text in the .html file.<\/p>
b. HTML elements (which consist of a start tag, text, and in most cases an end tag) may be embedded within other elements. In the above HTML, there are several instance of ... <\/b> appearing within other elements, as in The class meets at the following times: Sections 201 students: Tuesdays and Thursdays from 5:45-9:00. Section 210 students: Online students view the lectures on D2L. <\/p> <\/html><\/p> HTML is not valid if start tags and end tags are mixed in the incorrect order. For example: language.<\/li><\/b> In this case, the <\/li> end tag precedes the <\/b> tag, but since the boldface element Java<\/p> language is one of the list items, <\/b> should precede <\/li>.<\/p> Your task<\/p> Your 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:<\/p> 1. Identify tags. You may assume that whenever the < symbol appears, it begins a tag (of course, end tags begin with <\/).>. You may assume that the symbols < and > will not appear in the String unless they start or end a tag.<\/p> 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 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 (which have no corresponding end tag), the tag name should not be pushed onto the stack.<\/p> 3. When your program encounters an end tag, there are several possibilities:<\/p> a. If the stack is empty, then the HTML is invalid, and the validPage method should return false immediately.<\/p> b. Otherwise, pop thes stack. If the (popped) start tag matches the end tag, then the program should continue processing the rest of the String.<\/p> c. It the start tag and end tag do not match, then it depends on whether or not the start tag is type a 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 (i) 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 processing the String)<\/p> 4. If your program reaches the end of the HTML String, then it should return true of the stack is empty or if every remaining start tag on the stack if type b.<\/p> Here is an example of how your validPage should work on a small subset of the example HTML above. Assume the String passed as a parameter to validPage is all on a single line.<\/p> HTMLChecker.validPage( In addition, we will discuss the running times of various operations on different data structures.)<\/p> Tag<\/p> <\/td> Stack<\/p> <\/td> Tag<\/p> <\/td> Stack<\/p> <\/td> <\/tr> [center]<\/p> <\/td> [p ol li]<\/p> <\/td> <\/tr> [center h3]<\/p> <\/td> <\/p> <\/td> [p ol li b]<\/p> <\/td> <\/tr> <\/p> <\/td> [center h3 b]<\/p> <\/td> <\/b><\/p> <\/td> [ol li]<\/p> <\/td> <\/tr> <\/b><\/p> <\/td> [center h3]<\/p> <\/td> <\/p> <\/td> [ol li p]<\/p> <\/td> <\/tr> <\/h3><\/p> <\/td> [center]<\/p> <\/td> [ol li p li]<\/p> <\/td> <\/tr> <\/center><\/p> <\/td> []<\/p> <\/td> <\/li>*<\/p> <\/td> [ol]<\/p> <\/td> <\/tr> <\/p> <\/td> [p]<\/p> <\/td> <\/ol><\/p> <\/td> []<\/p> <\/td> <\/tr> [p ol]<\/p> <\/td> <\/p> <\/td> [p]<\/p> <\/td> <\/tr> <\/tbody> <\/table> Note that when the <\/li> tag is encountered (marked by *), several items are popped from the stack, since they are all type b start tags, which do not require end tags. If any of them were type a tags, at this point the validPage method would return false.<\/p> For this html String, in the end your validPage method should return true. This is valid HTML, because the only tag left on the stack ( ) is a type b tag, for which a <\/p> is optional.<\/p> Code I am providing<\/strong><\/p> If you download the hw3.jar file, you will see a partially completed version of the validHTML method which you must complete. Here is a portion of the code I am providing. The intent of the starter code is to relieve you of the burden of writing the string-manipulation part of the validHTML method (mainly, identifying and extracting tags, and determining if they are start or end tags), so that you can concentrate on the correct manipulation of the stack.<\/p> public static boolean validPage(String html) {<\/strong><\/p> \/\/ the stack that we'll use to save start tags for \/\/ which we are (possibly) expecting a corresponding \/\/ end tag. Whether the end tag is required or \/\/ optional depends on the type of the start tag (\"type a\" \/\/ or \"type b\") Stack \/\/ find the index of the first start tag in html (the parameter \/\/ String) int tagStartPosition = html.indexOf('<'); boolean isStartTag;<\/strong><\/p> while (tagStartPosition != -1) {<\/strong><\/p> int tagEndPosition = html.indexOf('>', tagStartPosition+1); if (tagEndPosition == -1) return false;<\/strong><\/p> String tag = html.substring(tagStartPosition+1, tagEndPosition);<\/strong><\/p> if (tag.charAt(0) == '\/') { tag = tag.substring(1); isStartTag = false;<\/strong><\/p> } else isStartTag = true;<\/strong><\/p> tagStartPosition = html.indexOf('<', tagEndPosition+1); }<\/strong><\/p> return false; \/\/ replace }<\/strong><\/p> In the JAR file, you will also find a class called HW3Tester. It calls validPage, passing it various examples of valid and invalid HTML. You can expect the html only to contain tags that I have specified in the starter code.<\/p> When your program is properly completed, the output of the main method should be<\/p> true false false true<\/p> You should test your code on other examples, since when the assignment is graded the grader may use additional examples as well.<\/p>",
"transcribed_text": "",
"related_book": {
"title": "Database Processing Fundamentals, Design, and Implementation",
"isbn": "133876705, 9781292107639, 1292107634, 978-0133876703",
"edition": "14th edition",
"authors": "David M. Kroenke, David J. Auer",
"cover_image": "https:\/\/dsd5zvtm8ll6.cloudfront.net\/si.question.images\/book_images\/1808.jpg",
"uri": "\/textbooks\/database-processing-fundamentals-design-and-implementation-14th-edition-1808",
"see_more_uri": "\/textbooks\/computer-science-webassembly-2534"
},
"question_posted": "2024-09-26 00:05:16",
"step_by_step_answer": "The Answer is in the image, click to view ...",
"students_also_viewed": [
{
"url": "\/study-help\/international-human-resource-management\/75-training-techniques-for-example-computerbased-classroom-onthejob-2123232",
"description": "75 Training techniques (for example, computerbased, classroom, on-the-job).",
"stars": 0
},
{
"url": "\/starkey-companys-sales-current-assets-and-current-liabilities-all-in",
"description": "Starkey Companys sales, current assets, and current liabilities (all in thousands of dollars) have been reported as follows over the last five years (Year 5 is the most recent year): Required: 1....",
"stars": 3
},
{
"url": "\/study-help\/questions\/java-your-task-is-to-write-a-class-called-htmlchecker-13563190",
"description": "JAVA. Your task is to write a class called HTMLChecker. As you may be aware, many resources of the World Wide Web are written in a markup language called HTML (Hypertext Markup Language). You do not...",
"stars": 3
},
{
"url": "\/study-help\/questions\/57-per-guest-annual-fixed-costs-total-742600-foad-the-11710869",
"description": "57 per guest Annual fixed costs total $742,600. Foad the reguirements: Requirement 1. Compute revenue and variable costs for each show. Solect the formula and enter the amounts to compute sales...",
"stars": 3
},
{
"url": "\/study-help\/questions\/suppose-that-a-learning-algorithm-is-trying-to-find-a-653539",
"description": "Suppose that a learning algorithm is trying to find a consistent hypothesis when the classifications of examples are actually random. There are n Boolean attributes, and examples are drawn uniformly...",
"stars": 3
},
{
"url": "\/study-help\/questions\/ho-designs-experienced-the-following-events-during-year-1-its-937664",
"description": "HO Designs experienced the following events during Year 1, its first year of operation:\\ \\ Started the business when it acquired $92,000 cash from the issue of common stock.\\ \\ Paid $39,000 cash to...",
"stars": 3
},
{
"url": "\/study-help\/questions\/equity-in-net-income-and-eliminating-entries-intercompany-asset-transfers-5510297",
"description": "Equity in Net Income and Eliminating Entries, Intercompany Asset Transfers and Services On January 1, 2018, Pohang Company acquired all of Suro Corporations voting common stock for $1,500,000. The...",
"stars": 3
},
{
"url": "\/study-help\/questions\/prevosti-farms-and-sugarhouse-pays-its-employees-according-to-their-793150",
"description": "Prevosti Farms and Sugarhouse pays its employees according to their job classification. The following employees make up Sugarhouse's staff: Employee Number Name and Address Payroll information...",
"stars": 3
},
{
"url": "\/study-help\/questions\/the-interviews-for-potential-candidates-group-of-answer-choices-2815303",
"description": "The interviews ___ for potential candidates. Group of answer choices is reserved are reserved am reserved",
"stars": 3
},
{
"url": "\/study-help\/cost-of-capital-in-managerial-finance\/are-pay-policies-typically-the-same-for-all-occupation-groups-2132142",
"description": "Are Pay Policies typically the same for all Occupation Groups in an organization?",
"stars": 3
},
{
"url": "\/study-help\/cost-of-capital-in-managerial-finance\/why-are-medians-sometimes-more-indicative-of-central-tendency-than-2132144",
"description": "Why are Medians sometimes more indicative of Central Tendency than are Averages?",
"stars": 3
},
{
"url": "\/study-help\/cost-of-capital-in-managerial-finance\/what-types-of-data-are-dimensional-relational-databases-in-both-2132133",
"description": "What types of data are Dimensional Relational Databases in both RDMSs and OLAP Databases primarily designed to hold?",
"stars": 3
}
],
"next_back_navigation": {
"previous": "\/study-help\/questions\/let-x-be-a-dataframe-with-1-0-0-rows-13563189",
"next": "\/study-help\/questions\/in-c-sharp-plz-create-c-classes-for-the-shapes-13563191"
},
"breadcrumbs": [
{
"name": "Study help",
"link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers"
},
{
"name": "Computer Science",
"link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers\/computer-science"
},
{
"name": "Databases",
"link": "https:\/\/www.solutioninn.com\/study-help\/questions\/computer-science-databases"
},
{
"name": "JAVA. Your task is to write a class called HTMLChecker. As you",
"link": "https:\/\/www.solutioninn.com\/study-help\/questions\/java-your-task-is-to-write-a-class-called-htmlchecker-13563190"
}
],
"skill_details": {
"skill_id": "656",
"skill_name": "Databases",
"parent_id": "8"
}
}CSC 300 Section 201, 210 Summer I 2017<\/b><\/h3> <\/center><\/p>
CSC 300<\/b><\/h3><\/center>
<\/td> <\/td> <\/p> <\/td>
<\/td> <\/td> <\/td> <\/td> <\/td> <\/td> <\/p> <\/td>
<\/td> \/\/ attempt to find the index of the end of the start tag <\/strong> <\/pre>
\/\/extract the tag <\/strong> <\/pre>
\/\/ determine if the tag is a start tag or and end tag <\/strong> <\/pre>
\/\/fill in the rest of the code here <\/strong> <\/pre>
\/\/ now we've reached the end of the string. Determine if \/\/ the String contained valid HTML or not <\/strong> <\/pre>