Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me out of this. I will be more than happy to give 5star rating to a

ID: 3645997 • Letter: P

Question

Please help me out of this. I will be more than happy to give 5star rating to a great work!!

Write a class named HtmlStripper.

Your class must contain the following methods:

public static void main (String[] args)
call the userInterface() method
public static void userInterface()
create a Scanner for console input
pass this Scanner to the getInput method
pass the Scanner returned from the getInput method to the processFile method
public static Scanner getInput(Scanner console)
prompt the user for a file name of a file containing an HTML webpage
create a Scanner to read from this file and return it
if the file does not exist, print a file does not exist message and exit the program gracefully (java should not cause the program to exit with an exception). You can use the File object methods to test for existence or use the try/catch technique.
public static void processFile(Scanner input)
Read the input file and print the file's text with all the HTML tags removed. A tag is any text between the characters < and >.

For example, if the file contained the following lines (Exercise 6.10):

<html>
<head>
<title>My web page</title>
</head>
<body>
<p>There are many pictures of my cat here,
as well as my <b>very cool</b> blog page,
which contains <font color="red">awesome
stuff about my trip to Vegas.</p>

Here's my cat now:<img src="cat.jpg">
</body>
</html>

Your program should output the following text:

My web page


There are many pictures of my cat here,
as well as my very cool blog page,
which contains awesome
stuff about my trip to Vegas.

Here's my cat now:

You may assume that the file is a well-formed HTML document and that there are no < or > characters inside tags.

Explanation / Answer

please rate - thanks

sample input file and output

import java.util.*;
import java.io.*;
public class HtmlStripper
{public static void main(String[] args)throws FileNotFoundException
{userInterface();
                  
}
public static void userInterface()throws FileNotFoundException
{Scanner in=new Scanner(System.in);
Scanner file=getInput(in);
processFile(file);
}
public static Scanner getInput(Scanner console)throws FileNotFoundException
{System.out.print("Enter name of HTML file: ");
String filename=console.nextLine();
Scanner input=null;
try
   {input=new Scanner(new File(filename));
    }catch (FileNotFoundException e)
        {System.out.println("FileNotFoundException: "+ e.getMessage());
        System.exit(0);
       }
return input;
}
public static void processFile(Scanner input)
{String buffer;
boolean html=false;
int i;
while(input.hasNextLine())
    {buffer=input.nextLine();
    for(i=0;i<buffer.length();i++)
           if(buffer.charAt(i)=='<')
                  html=true;
            else if(buffer.charAt(i)=='>'&&html)
                  html=false;
            else if(!html)
                  System.out.print(buffer.charAt(i));
        System.out.println();   
                    
    }  
}


}