Question: Define a class called SymbolBalance in the provided empty SymbolBalance.java file. Make sure that all { }s, ( )'s, [ ]'s, s, and /*

Define a class called SymbolBalance in the provided empty SymbolBalance.java file.

Make sure that all { }’s, ( )'s, [ ]'s, " "’s, and /* */’s are properly balanced. Make sure to ignore characters within literal strings and comment blocks.

You do not need to handle single line comments (those that start with //), literal characters (things in single quotes), or the diamond operator(<>).

There are a number of error cases:

The file ends with one or more opening symbols missing their corresponding closing symbols.

There is a closing symbol without an opening symbol.

There is a mismatch between closing and opening symbols (for example: { [ } ] ).

Your program should output whether or not the symbols are all appropriately balanced. If they are not, indicate which error condition occurred and what symbol type caused the problem.

You will need to write your own stack class for this. It should be generic (in this particular case you will be pushing Character objects on it, but it should be capable of handling any object reference). Call your stack class: MyStack.java .You should use java.util.LinkedList as an instance variable in your MyStack class, but in the implementation of your stack methods, you are only allowed to use its basic list operations, not the stack operations themselves (that is, do not use LinkedList’s native push and pop methods). Your stack should implement the following methods:

Public void push(AnyType x)

Public AnyType pop()

Public AnyType peek()

Public boolean isEmpty()

Public int size()

Define this class in the provided empty MyStack.java file.

Here is an example. You are given a file with the following contents:

public static final void main( String [ ) args) {

System.out.println("Hello.");

}

}

You would run your program like this:

java SymbolBalance Test.java

and the output should be something like:

Unbalanced! Symbol ) is mismatched.

Step by Step Solution

3.34 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement this assignment follow these steps Step 1 MyStackjava Implementation 1 Define the MyStack Class This class should be a generic stack implementation using javautilLinkedList 2 Implement th... View full answer

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

Document Format (2 attachments)

PDF file Icon

60920a3c0490b_22741.pdf

180 KBs PDF File

Word file Icon

60920a3c0490b_22741.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!