Question: having issues with this piece of code for a programming project, when I test the program it does not correctly process the test files. Mainly
having issues with this piece of code for a programming project, when I test the program it does not correctly process the test files. Mainly for "Unmatch" and "mismatch" but it also puts the wrong output for all almost all tests. delimiters are not properly encountered. It won't allow me to send the full code but here is the portion where I think the issue is
Stack code :
Stack delimiterStack new Stack;
Character ch;
boolean mismatchFound false;
Process each character in the file
while ch checker.nextChar null && mismatchFound
switch ch
case :
case :
case :
delimiterStack.pushch; Push opening delimiters onto the stack
break;
case :
case :
case :
if delimiterStackisEmpty
System.out.printfUnmatched closing delimiter c at sn ch checker.getPosition;
mismatchFound true;
else
char openDelimiter delimiterStack.pop;
if isMatchingPairopenDelimiter ch Mismatched delimiters
System.out.printfMismatched delimiter c at sn ch checker.getPosition;
mismatchFound true;
break;
if mismatchFound && delimiterStack.isEmpty
char unmatchedOpenDelimiter delimiterStack.pop;
System.out.printfUnmatched opening delimiter c at the end of the filen unmatchedOpenDelimiter;
else if mismatchFound
System.out.printlnAll delimiters are properly matched.";
try
checker.close;
catch IOException e
System.out.printlnError closing the file.";
scanner.close;
this is the requirement:
The second class should contain the main method. It should read in the file name from the keyboard until a valid file name is entered and then create an object of the first class. It should then repeatedly call the method that returns the next character until it returns a null character indicating the end of the file or until a mismatch of delimiters is encountered. If the character is a left delimiter it should be pushed onto a delimiter stack. If it is a right delimiter, the stack should be popped and a check should be made to ensure that the delimiters are of a matching type. If the delimiters do not match, a message should be displayed indicating what delimiter was encountered and at what position. You may use the defined Java Stack class.
Here is test coded for unmatched and another:
public class TestCase
public static void mainString args
int x ;
if x
System.out.printlnx is greater than ;
public class TestCase
public static void mainString args
This is a comment with unmatched parenthesis
String s "This is a string with bracketsbraces;
This is a multiline comment
with unmatcheddelimiters
System.out.printlnEverything is fine";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
