descriptionIn this assignment, you’ll write a Java program which asks the user to enter the name of a plain text file. The program reads the file and then outputs an html version according to the guidelines provided.
The purpose of the assignment is to provide some practice reading and writing files as well as reinforcing what you’ve learned about handling Strings
If you’re unfamiliar with the basics of HTML or need a refresher, you can learn more at w3schools.
file namesThe user should enter the name of an input file which ends “.txt”. The output file should have the same name as the input file, except that instead of ending “.txt”, it should end “.html”
the rulesWe’ll only be working with a very small part of HTML in this assignment. You’re welcome to add more if you’d like, but at a minimum, the HTML output should begin:
and should end:
Other transformations from the input file to HTML should be done according to the following:
If a line begins and ends with an underscore character (‘_’), the program should output the contents of that line (minus the leading and trailing underscores) within an h1 header tag. For example, if the line contained the text_Big Important Point_the program would output:
Big Important Point
Blank lines are replaced with HTML paragraph tags, i.e.,
(You do not have to close paragraphs with an XHTML-style closing paragraph tag).
Lines that begin with a ‘-‘ character (i.e. a minus sign) are considered to be bullet points of an unordered list.In your output, lists should begin:
- Each bullet point in the list will consist of the characters of the line following the ‘-‘ in the input, and will be enclosed in list item tags, i.e.,
- text following the ‘-‘
Lists should end:
So for example, if in the input file we see:- turkey- lettuce- tomato- little bit of mayoYour program would output
- little bit of mayo
Any line that doesn’t match any of the previous rules will be output as is, but with a line break tag
at the end.
An ExampleIf the input file is:
_shanty_Who lives in a pineapple under the sea?Spongebob Squarepants- absorbent- yellow- porousis he, Spongebob SquarepantsThe program would output:
Who lives in a pineapple under the sea?
is he, Spongebob Squarepants
which, when rendered in a web browser, would look something like:
Who lives in a pineapple under the sea?Spongebob Squarepants
is he, Spongebob Squarepants
outputting URLsAny text in the input file of the form [[X][Y]] should be treated as a hyperlink, where X is the URL, and Y is the text to display on the screen.
You are not required to handle the possibility that one of these blocks begins and ends on different lines of the input file.
exceptionsRemember that you are not required to handle FileNotFoundException using try-catch-finally blocks. We’ll cover these later in the semester. For now, it is only necessary to add the clause throws FileNotFoundException to each function where you write new File or any function that calls a function that has a throws FileNotFoundException clause. You’ll find examples of this in our classnotes. Please use Scanner class and Print Stream for inputs and outputs. Also, please stick to booleans, if statements, loops, etc. Do not create your own objects, stick to the objects already made in Java.