QuestionQuestion

Create a Java command line program that reads a file (whose name is given as a command line argument) and prints all of the Java style comments the file contains. a comment is any text after a // and between /* and */ that is not inside of quotes i.e. bad string // not a comment; does not start a comment. You may assume the file is valid Java code (i.e. no syntax errors) and that it can fit in memory. Paste your code in the text box below. Your code should consist of just one file.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class CommentExtractor
{
private static void printStr( String msg, String sb )
{
String s = sb.toString().trim();
if(s.length() > 0)
System.out.println(s + "\r\n");
}

    private static boolean testMatch(String str, int pos, String match)
    {
       if(pos + match.length() > str.length())
            return false;
       for(int i=0 ; i < match.length() ; i++)
            if(str.charAt(pos+i) != match.charAt(i))
                return false;
       return true;
    }
   
    private static boolean whiteSpace(char ch)
    {
       if(ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
       return true;
       else
       return false;
    }

   
private static void getComments(String... names)
    {
for(String name : names) {
StringBuilder sb = new StringBuilder();
try
{...
$10.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats