Question: Part 1 Create a simple stack class based on the provided stack interface implemented using an array. Pass All the unit test that are provided
Part
Create a simple stack class based on the provided stack interface
implemented using an array.
Pass All the unit test that are provided for it
Part
Create a method that checks if a string has balanced brackets, parentheses
square braces using your stack.
Create Unit Tests for it
Pass All those tests
No need to update this file
public interface StackInterface
Insert a new item into the stack.
@param item the item to insert.
public void pushItem item;
Remove the most recently inserted item from the stack.
public void pop;
Get the most recently inserted item in the stack. Does not alter the stack.
public Item top;
Return and remove the most recently inserted item from the stack.
@return the most recently inserted item in the stack.
Item topAndPop;
Test if the stack is logically empty.
@return true if empty, false otherwise.
public boolean isEmpty;
Make the stack logically empty.
public void makeEmpty;
Return the size of the stack.
public int size;
import java.util.HashMap;
scroll down to update this file implement balanced method
You need to create MainTest.jave that test all cases of this class.
public class Main
public static void mainString args
String input ;
String leftBrackets ;
String rightBrackets ;
ifbalancedinputleftBrackets,rightBrackets
System.out.printlnBalanced;
else
System.out.printlnUnbalanced;
public static boolean balancedString checkBalanced, String leftBrackets, String rightBrackets
implement this method
return false;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.EmptyStackException;
import org.junit.jupiter.api.Test;
No need to update this file
class TestStack
@Test
public void testSizeStackEmpty
Stack stack new Stack;
assertEquals stack.size;
@Test
public void testisEmptyStackEmpty
Stack stack new Stack;
assertTruestackisEmpty;
@Test
public void testTopEmptyStack throws EmptyStackException
Stack stack new Stack;
assertThrowsEmptyStackExceptionclass, stack.top "Exception not throw as expected";
@Test
public void testPopEmptyStack throws EmptyStackException
Stack stack new Stack;
assertThrowsEmptyStackExceptionclass, stack.pop "Exception not throw as expected";
@Test
public void testTopAndPopEmptyStack throws EmptyStackException
Stack stack new Stack;
assertThrowsEmptyStackExceptionclass, stack.topAndPop "Exception not throw as expected";
@Test
public void testisEmptyAfterOnePush
Stack stack new Stack;
stack.push;
assertFalsestackisEmpty;
@Test
public void testSizeAfterOnePush
Stack stack new Stack;
stack.push;
assertEquals stack.size;
@Test
public void testTopAfterOnePush
Stack stack new Stack;
stack.push;
Integer expected ;
assertEqualsexpected stack.top;
@Test
public void testTopAfterPushPop throws EmptyStackException
Stack stack new Stack;
stack.push;
stack.pop;
assertThrowsEmptyStackExceptionclass, stack.top "Exception not throw as expected";
@Test
public void testTopAfterPushPushPop
Stack stack new Stack;
stack.push;
stack.push;
stack.pop;
Integer expected ;
assertEqualsexpected stack.top;
@Test
public void testSizeAfterMultiplePush
Stack stack new Stack;
stack.push;
stack.push;
stack.push;
stack.push;
assertEquals stack.size;
@Test
public void testSizeAfterPushPop
Stack stack new Stack;
stack.push;
stack.pop;
assertEquals stack.size;
@Test
public void testisEmptyAfterMultiplePush
Stack stack new Stack;
stack.push;
stack.push;
stack.push;
stack.push;
assertFalsestackisEmpty;
@Test
public void testTopAfterMultiplePush
Stack stack new Stack;
stack.push;
stack.push;
stack.push;
stack.push;
Integer expected ;
assertEqualsexpected stack.top;
@Test
publi
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
