Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a java program that generates an outline representation of an HTML document based on the requirements below. Write a program called HTMLSummarizer.java that reads

Create a java program that generates an outline representation of an HTML document based on the requirements below.

Write a program called HTMLSummarizer.java that reads in an HTML file and outputs the corresponding outline representation. Your HTMLSummarizer class must implement the provided Tester interface and also contain the main() method where your program starts running. This is because your program will be tested via this interface. The interface contains a single method:

public ArrayList compute( Scanner input );

This method must perform the required computation.

Input

The method takes a Scanner object, which contains a valid HTML file. You may assume that every start tag is properly matched with an end tag, and that there are no errors in the input.

Hint: Use the provided HTMLScanner object to easily parse the input by using its two methods: hasNextTag() and nextTag().

Semantics

The HTML file will contain 0 or more tags.

The depth of a void tag or an element is the number of elements that surround it. For example, the depth of element b in Figure 1 is 3.

An element or void tag is a child of another element, if it is contained in that element and is of depth one greater than the element. For example, in Figure 1, b is a child of p, but is not a child of body. Whereas, p, hr, p, and h1 are all children of body. All tags whose names begins with a ! are to be ignored. For example, tags of the form

and " +

"

Bold Example: bold

" +

"" +

"";

private static String [] testOutput6 = { "html 1",

" body 4",

" h1 0",

" p 2",

" hr",

" hr",

" br",

" p 1",

" b 0" };

private static Scanner mkTest( String input ) {

return new Scanner( input );

}

private static ArrayList mkOutput( String [] output ) {

ArrayList al = new ArrayList();

for( String s : output ) {

al.add( s );

}

return al;

}

private static boolean doTest( String input, String [] output ) {

Tester t = new HTMLSummarizer();

ArrayList al = t.compute( mkTest( input ) );

System.out.println( "Input: " );

System.out.println( input );

System.out.println( "Generated output" );

for( String s : al ) {

System.out.println( s );

}

System.out.println( "Expected output" );

for( String s : output ) {

System.out.println( s );

}

System.out.println( "---------------------------------------------------" );

return al != null && al.equals( mkOutput( output ) );

}

@Test

void testEmpty() {

assertTrue( doTest( testInput0, testOutput0 ), "Empty Test" );

}

@Test

void test1() {

assertTrue( doTest( testInput1, testOutput1 ), "Single element tag" );

}

@Test

void test2() {

assertTrue( doTest( testInput2, testOutput2 ), "Single void tag" );

}

@Test

void test3() {

assertTrue( doTest( testInput3, testOutput3 ), "Single nesting test" );

}

@Test

void test4() {

assertTrue( doTest( testInput4, testOutput4 ), "Multiple nestings" );

}

@Test

void test5() {

assertTrue( doTest( testInput5, testOutput5 ),

"Multiple nestings and levels" );

}

@Test

void test6() {

assertTrue( doTest( testInput6, testOutput6 ), "Assignment example" );

}

}

Sample Input Sample Output htm> html 1 tml> body> hl>My First Heading p My first paragraph body 4 h1 0 hr hr Another ruler ... o more rulers b 0 LI should be ignored --> p>Bold Example: bold

k/body> html> Sample Input Sample Output htm> html 1 tml> body> hl>My First Heading p My first paragraph body 4 h1 0 hr hr Another ruler ... o more rulers b 0 LI should be ignored --> p>Bold Example: bold

k/body> html>

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

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

How does debt levels change CPK S value

Answered: 1 week ago