Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This should be done in java. In this program, you are going to read in a file, a

ID: 3833065 • Letter: T

Question

This should be done in java.

In this program, you are going to read in a file, and you are going to parse it onto a stack and determine if it is syntactically correct. You will check for all open and close curly braces, open and closed parentheses, and you will check for all double quotes. You should also allow the user to choose their own file. This should be done graphically. Please use your own implementation of a stack.

Start with something like this:

public class MainFrame {

public static void main(String[] args) {

// Create an instance of the frame

JFrame myFrame = new JFrame("Basic Example");

// set the default close operation (i.e. when they click the x button) myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// add the panel to the frame myFrame.getContentPane().add(new MainPanel());

// this make sure whatever is in the panel fits in the frame myFrame.pack();

// make sure the frame is visible - it's not visible by default myFrame.setVisible(true);

}

}

Explanation / Answer

code to check balanced paranthesis

import java.util.*;

public class MainFrame
{
public static void main(String[] args)
{
   /* accepting input from user from input console*/
Scanner scan = new Scanner(System.in);
/* Creating Stack */
Stack<Integer> stk = new Stack<Integer>();
System.out.println("Parenthesis Matching Test ");
/* Accepting expression */
System.out.println("Enter expression");
String exp = scan.next();
int len = exp.length();
System.out.println(" Matches and Mismatches: ");
for (int i = 0; i < len; i++)
{
char ch = exp.charAt(i);
if (ch == '(')
stk.push(i);
else if (ch == ')')
{
try
{
int p = stk.pop() + 1;
System.out.println("')' at index "+(i+1)+" matched with ')' at index "+p);
}
catch(Exception e)
{
System.out.println("')' at index "+(i+1)+" is unmatched");
}
}
}
while (!stk.isEmpty() )
System.out.println("'(' at index "+(stk.pop() +1)+" is unmatched");
}
}

like wise we can also check the double quotes

graphical options can be enabled by using Jframes as you already mentioned in the question that code looks good

All THE BEST

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote