Question: Comment Scrapeir roblem Description: A well-written program will use comments judiciously to document the function and structure of a piece of high-level code. While this

 Comment Scrapeir roblem Description: A well-written program will use comments judiciouslyto document the function and structure of a piece of high-level code.

Comment Scrapeir roblem Description: A well-written program will use comments judiciously to document the function and structure of a piece of high-level code. While this is helpful, it might also be useful to have a tool that can read through a large code file and pull out all of the comments. This is where you come in. Write a program in Java that prompts the user for a Java source file (for example, Hangman.java) Your program will create another file which uses the same name, but with the".txt" file extension (example, Hangman.txt). In this output file, you will write only the comments, with line numbers. Remember in Java, there are two types of comments: .Single line comments begin with// and include everything else on that line . Multiline comments begin with/ and end with/ The output should include only the comment text (including the punctuation/ and*/or//) but nothing else! Each line of output (in your text file) should be preceded with a line number and colon. See Required Output below for an example Create a robust solution by catching any I/O Exceptions that may occur during your program execution. As examples, the program should handle a missing file gracefully, or the situation in which you cannot create the output file (due to permissions, for example) Notes: A Multiline comment may begin and end in a single line /*This is my code A multiline comment may have Java code before and after it. int total, / Amount available */ used You should ignore any single line comments inside a multiline comment. . . **This is my program // Weird comment! ** The following situations do not need to be handled, but can be for extra credit: int total, *Amount available used Another comment */; int total, Amount available */ used / Another comment In the cases above, the first comment should always be picked up. For extra credit, pick up both comments, but not the intervening Java code Here are other weird ones. Not required, but can you properly handle them? . o System.out.println ("No // comment here!") o System.out.println ("Nocomment here! /") o System.out.println ("There is a" // comment here! " comment. ")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!