Question
CheckParenthesus.java: import MyStack.StackList; import java.util.Scanner; public class CheckParentheses { public static void main (String[] args) { Scanner scan = new Scanner (System.in); StackList myStack =
CheckParenthesus.java:
import MyStack.StackList;
import java.util.Scanner;
public class CheckParentheses
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
StackList myStack = new StackList();
String expression, keep_going="y";
int index;
boolean properlyNested;
while (keep_going.charAt(0) == 'y' || keep_going.charAt(0) == 'Y')
{
// insert your code here below
System.out.println(" ");
System.out.print("Want to continue with another expression? [y or n]: ");
keep_going = scan.nextLine();
}
}
}
EmptyListException.java:
package MyStack;
public class EmptyListException extends RuntimeException { // no-argument constructor public EmptyListException() { this( "List" ); // call other EmptyListException constructor } // end EmptyListException no-argument constructor
// one-argument constructor public EmptyListException( String name ) { super( name + " is empty" ); // call superclass constructor } // end EmptyListException one-argument constructor } // end class EmptyListException
List.java:
package MyStack;
public class EmptyListException extends RuntimeException { // no-argument constructor public EmptyListException() { this( "List" ); // call other EmptyListException constructor } // end EmptyListException no-argument constructor
// one-argument constructor public EmptyListException( String name ) { super( name + " is empty" ); // call superclass constructor } // end EmptyListException one-argument constructor } // end class EmptyListException
StackList.java:
package MyStack;
public class StackList { private List a_stack;
// no-argument constructor public StackList() { a_stack = new List( "stack" ); } // end StackComposition no-argument constructor
// add object to stack public void push( Object object ) { a_stack.insertAtFront( object ); } // end method push
// remove object from stack public Object pop() throws EmptyListException { return a_stack.removeFromFront(); } // end method pop
// determine if stack is empty public boolean empty() { return a_stack.isEmpty(); } // end method isEmpty
// output stack contents public void print() { a_stack.print(); } // end method print } // end class StackList
Write a Java program (CheckParentheses.java), with the help of the StackList class (a Linked List implementation of Stack) as demonstrated and provided by your instructor, to check on any given arithmetic expression to determine whether the expression is properly nested with parentheses or not. See a sample run of the program below: Enter an arithmetic expression with parentheses: (a+b)*(c-d) (a-b) (a+b) (e-d)V(a-b) is properly nested with parentheses: Want to continue with another expression? ly or nl: y Enter an arithmetic expression with parentheses: (a-c)/(bta)-d)*c (a-c)/(b-a)-d)*c is properly nested with parentheses! Want to continue with another expression? ly or nl: y Enter an arithmetic expression with parentheses: ((atb)*(-c) (a+b)*(-c) is NOT properly nested with parentheses! Want to continue with another expression? ly or nly Enter an arithmetic expression with parentheses: (b+c)*c)(c-a (b+c)*c(c-a is NOT properly nested with parentheses! want to continue with another expression? ly or nl: y Enter an arithmetic expression with parentheses: (a*(b-c)) (a*(b-c)) is NOT properly nested with parentheses! Want to continue with another expression? ly or nl: n All base java files are found inside a folder named Lab8_part2. Please complete the CheckParentheses program as required for Part II. Write a Java program (CheckParentheses.java), with the help of the StackList class (a Linked List implementation of Stack) as demonstrated and provided by your instructor, to check on any given arithmetic expression to determine whether the expression is properly nested with parentheses or not. See a sample run of the program below: Enter an arithmetic expression with parentheses: (a+b)*(c-d) (a-b) (a+b) (e-d)V(a-b) is properly nested with parentheses: Want to continue with another expression? ly or nl: y Enter an arithmetic expression with parentheses: (a-c)/(bta)-d)*c (a-c)/(b-a)-d)*c is properly nested with parentheses! Want to continue with another expression? ly or nl: y Enter an arithmetic expression with parentheses: ((atb)*(-c) (a+b)*(-c) is NOT properly nested with parentheses! Want to continue with another expression? ly or nly Enter an arithmetic expression with parentheses: (b+c)*c)(c-a (b+c)*c(c-a is NOT properly nested with parentheses! want to continue with another expression? ly or nl: y Enter an arithmetic expression with parentheses: (a*(b-c)) (a*(b-c)) is NOT properly nested with parentheses! Want to continue with another expression? ly or nl: n All base java files are found inside a folder named Lab8_part2. Please complete the CheckParentheses program as required for PartStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started