Question: I have provided the program but I need to show screenshots of the output from the executable program. Can you provide my request? Class 1

I have provided the program but I need to show screenshots of the output from the executable program. Can you provide my request? Class 1: `JavaFileAnalyzer.java`
// JavaFileAnalyzer.java
// Name: Elbert Clements
// Project: Delimiter Matching
// Date: 8/25/2024
// Description: This class encapsulates the input file and provides methods to read characters excluding comments and literals.
import java.io.*;
public class JavaFileAnalyzer {
private BufferedReader reader;
private int lineNumber;
private int charNumber;
private String currentLine;
private int currentIndex;
public JavaFileAnalyzer(String fileName) throws FileNotFoundException {
reader = new BufferedReader(new FileReader(fileName));
lineNumber =0;
charNumber =0;
currentLine = null;
currentIndex =0;
}
public char getNextChar() throws IOException {
while (true){
if (currentLine == null || currentIndex >= currentLine.length()){
currentLine = reader.readLine();
if (currentLine == null){
return '\0'; // End of file
}
lineNumber++;
currentIndex =0;
}
char c = currentLine.charAt(currentIndex++);
charNumber++;
// Skip comments and literals
if (c =='/' && currentIndex < currentLine.length() && currentLine.charAt(currentIndex)=='/'){
currentLine = null; // Skip single-line comment
continue;
} else if (c =='/' && currentIndex < currentLine.length() && currentLine.charAt(currentIndex)=='*'){
// Skip multi-line comment
currentIndex++;
while (true){
if (currentLine == null || currentIndex >= currentLine.length()){
currentLine = reader.readLine();
if (currentLine == null){
return '\0'; // End of file
}
lineNumber++;
currentIndex =0;
}
if (currentLine.charAt(currentIndex)=='*' && currentIndex +1< currentLine.length() && currentLine.charAt(currentIndex +1)=='/'){
currentIndex +=2;
break;
}
currentIndex++;
}
continue;
} else if (c =='"'|| c =='\''){
// Skip string and character literals
char quote = c;
while (true){
if (currentLine == null || currentIndex >= currentLine.length()){
currentLine = reader.readLine();
if (currentLine == null){
return '\0'; // End of file
}
lineNumber++;
currentIndex =0;
}
c = currentLine.charAt(currentIndex++);
if (c == quote){
break;
}
}
continue;
}
return c;
}
}
public String getCurrentPosition(){
return "Line: "+ lineNumber +", Char: "+ charNumber;
}
}
Class 2: `DelimiterMatcher.java`
// DelimiterMatcher.java
// Name: Elbert Clements
// Project: Delimiter Matching
// Date: 8/25/2024
// Description: This class contains the main method to read the file name, create an object of JavaFileAnalyzer, and check for matching delimiters.
import java.io.*;
import java.util.*;
public class DelimiterMatcher {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
JavaFileAnalyzer analyzer = null;
while (analyzer == null){
System.out.print("Enter the Java source file name: ");
String fileName = scanner.nextLine();
try {
analyzer = new JavaFileAnalyzer(fileName);
} catch (FileNotFoundException e){
System.out.println("File not found. Please try again.");
}
}
Stack stack = new Stack<>();
try {
char c;
while ((c = analyzer.getNextChar())!='\0'){
if (c =='('|| c =='{'|| c =='['){
stack.push(c);
} else if (c ==')'|| c =='}'|| c ==']'){
if (stack.isEmpty()){
System.out.println("Unmatched "+ c +" at "+ analyzer.getCurrentPosition());
return;
}
char last = stack.pop();
if (!isMatchingPair(last, c)){
System.out.println("Mismatched "+ last +" and "+ c +" at "+ analyzer.getCur

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 Programming Questions!