Question: import static org.junit.Assert.*; import java.util.LinkedList; import org.junit.Test; public class StackExerciseTest { @Test(timeout = 100) public void isBalancedParenthesestest1() { String str = [](); assertTrue(StackExercise.isBalancedParentheses(str)); } @Test(timeout
import static org.junit.Assert.*; import java.util.LinkedList; import org.junit.Test; public class StackExerciseTest { @Test(timeout = 100) public void isBalancedParenthesestest1() { String str = "[]()"; assertTrue(StackExercise.isBalancedParentheses(str)); } @Test(timeout = 100) public void isBalancedParenthesestest2() { String str = "[[](())]"; assertTrue(StackExercise.isBalancedParentheses(str)); } @Test(timeout = 100) public void isBalancedParenthesestest3() { String str = "[()]](())]"; assertEquals(false, StackExercise.isBalancedParentheses(str)); } @Test(timeout = 100) public void revLinkedListtest1() { LinkedList lst = new LinkedList(); lst.add("A"); lst.add("B"); lst.add("C"); String ret = "[C, B, A]"; assertEquals(ret, StackExercise.revLinkedList(lst).toString()); } @Test(timeout = 100) public void revLinkedListtest2() { LinkedList lst = new LinkedList(); lst.add("A"); lst.add("B"); lst.add("C"); lst.add("D"); lst.add("E"); String ret = "[E, D, C, B, A]"; assertEquals(ret, StackExercise.revLinkedList(lst).toString()); } @Test(timeout = 100) public void revLinkedListtest3() { LinkedList lst = new LinkedList(); lst.add("A"); String ret = "[A]"; assertEquals(ret, StackExercise.revLinkedList(lst).toString()); } @Test(timeout = 100) public void postfixEvaluatetest1() { String str = "1 2 +"; assertEquals(3, StackExercise.postfixEvaluate(str)); } @Test(timeout = 100) public void postfixEvaluatetest2() { String str = "1 2 3 * + 4 +"; assertEquals(11, StackExercise.postfixEvaluate(str)); } @Test(timeout = 100) public void postfixEvaluatetest3() { String str = "8 5 * 7 4 2 + * +"; assertEquals(82, StackExercise.postfixEvaluate(str)); } @Test(timeout = 100) public void postfixEvaluatetest4() { String str = "6 8 2 / 1 - *"; assertEquals(18, StackExercise.postfixEvaluate(str)); } }
I need a code for my StackExercise class
import java.util.LinkedList; import java.util.Stack; public class StackExercise { /* * Given an expression string exp, * write a program to examine whether the pairs and * the orders of parenthesis are correct in exp. * For example, the program should print true for exp = [()[]] * and false for exp = [()[]) */ /** * * @param str * @return true if balanced; false is unbalanced */ public static boolean isBalancedParentheses(String str) { return true; } /* * * Reverse the all the items in the linkedlist and return the return the head of the * reversed one, for example: A -> B -> C should be reversed as: C->B->A */ /** * @param lst - the linkedlist to be reversed * @return the linkedlist with all items reversed - */ public static LinkedList revLinkedList(LinkedList lst) { return lst; } /* This function evaluates "postfix" expressions (also called "Reverse Polish * Notation"), which are mathematical expressions but with the operators placed * after operands instead of between. * For example: 1 + 2 * 3 + 4 is written as 1 2 3 * + 4 + */ /** * * @param str * @return the result of postfix expression */ public static int postfixEvaluate(String exp) { return -1; // remove this line } } 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
