Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the BRIDGES SLelement class, instead of the MyNode class. This class is named MyBridgesStack. Along with all methods defined in StackInterface, MyBridgesStack must implement

Use the BRIDGES SLelement class, instead of the MyNode class. This class is named MyBridgesStack. Along with all methods defined in StackInterface, MyBridgesStack must implement a public void method named visualize. The visualize method produces a BRIDGES URL and should be used to generate BRIDGES visualizations. How would I implement the visualize method?

StackInterface attached as well as MyBridgesTester. Thanks.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

An interface for the ADT stack @author Frank M. Carrano @author Timothy M. Henry @version 4.0 public interface StackIntertace Adds a new entry to the top of this stack @param newEntryAn object to be added to the stack. */ public void push(T newEntry); Removes and returns this stack's top entry. @returnThe object at the top of the stack. @throws if the stack is empty before the operation. */ public T pop(); /**Retrieves this stack's top entry @returnThe object at the top of the stack. @throwsEmptyStackExceptign if the stack is empty. */ public T peek(); /**Detects whether this stack is empty. public boolean isEmpty(); @ret if the stack is empty. */ Removes all entries from this stack. */ public void clear(); } // end StackInterface import static org.junit.Assert.* import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.EmptyStackException; import org.junit.Before; import org.junit.FixMethodorder; import org.junit.Test; import org.junit.runners.MethodSorters; @FixlethodOrder (MethodSorters. NAME ASCENDING) public class MyBridgesStackTest 1 MyBridgesStack stack; private String nl,n2,n3; * @throws java.lang.Exception @Before public void setUp) throws Exception i stacknew MyBridgesStack); n1"Able"; n2"Baker"; n3"Charlie"; private void pushAllElements)f stack.push (n1); stack.push (n2); stack.push (n3); eTest public final void visualizeTest) final ByteArrayOutputStream myOut - new ByteArrayOutputStream); System.setOut (new PrintStream(myOut)); pushA1lElements(); stack.visualize) final String standardOutput-myOut.toString); assertTrue(standardoutput.contains ("http://bridges-cs.herokuapp.com/")); * Test push onto an empty stack eTest public final void testPush1) [ stack.push("Rodney Ram"): assertEquals (stack.peek(), "Rodney Ram") * Test push onto a stack with elements eTest public final void testPush2) pushA1lElements(); stack.push("Rodney Ram"): assertEquals (stack.peek(), "Rodney Ram") * Test push onto a full stack Test public final void testPush3) pushA1lElements(); stack.push("Alan Turing"); stack.push( "Ada Lovelace"); stack.push("Adm. Grace Hopper") eTest public final void testPush4) pushA1lElements(); stack.push(""); assertEquals("", stack.peek )) * Test method for pop) an empty stack eTest (expected -EmptyStackException.class) public final void testPop1) f stack.pop O; * Test method for pop) after push eTest public final void testPop2) pushA1lElements(); assertEquals("Charlie", stack.pop)); * Test method for pop() after clear() @Test (expected EmptyStackException.class) public final void testPop3) f pushA1lElements(); stack.clear: stack.pop); * Test peek() before pushing anything eTest (expected -EmptyStackException.class) public final void testPeek1) f stack.peek); * Test peek() after push eTest public final void testPeek2) pushA1lElements(); assertEquals("Charlie", stack.peek)) * Test peek() after push & pop eTest public final void testPeek3) pushA1lElements(); stack.pop); assertEquals( "Baker", stack.peek)) * Test peak after clear @Test (expected EmptyStackException.class) public final void testPeek4) pushA1lElements(); stack.clear: stack.peek); * Test method for isEmpty) initially eTest public final void testIsEmpty1) assertTrue(stack.isEmpty()): * Test method for isEmpty) after push eTest public final void testIsEmpty2) pushA1lElements(); assertFalse(stack.isEmpty)): * Test method for isEmpty) after push & pop eTest public final void testIsEmpty3) pushA1lElements(); stack.pop); assertFalse(stack.isEmptyO); * Test method for isEmpty) after push & pops eTest public final void testIsEmpty4) pushA1lElements(); stack.pop); stack.pop); stack.pop); assertTrue(stack.isEmpty)) * Test method for isEmpty) after clear eTest public final void testIsEmpty5) pushA1lElements(); stack.clear: assertTrue(stack.isEmpty)) * Test method for clear() after initialization eTest public final void testClear10 stack.clear: assertTrue(stack.isEmpty)) * Test method for clear() after pushing eTest public final void testClear2) pushA1lElements(); stack.clear: assertTrue(stack.isEmpty)) An interface for the ADT stack @author Frank M. Carrano @author Timothy M. Henry @version 4.0 public interface StackIntertace Adds a new entry to the top of this stack @param newEntryAn object to be added to the stack. */ public void push(T newEntry); Removes and returns this stack's top entry. @returnThe object at the top of the stack. @throws if the stack is empty before the operation. */ public T pop(); /**Retrieves this stack's top entry @returnThe object at the top of the stack. @throwsEmptyStackExceptign if the stack is empty. */ public T peek(); /**Detects whether this stack is empty. public boolean isEmpty(); @ret if the stack is empty. */ Removes all entries from this stack. */ public void clear(); } // end StackInterface import static org.junit.Assert.* import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.EmptyStackException; import org.junit.Before; import org.junit.FixMethodorder; import org.junit.Test; import org.junit.runners.MethodSorters; @FixlethodOrder (MethodSorters. NAME ASCENDING) public class MyBridgesStackTest 1 MyBridgesStack stack; private String nl,n2,n3; * @throws java.lang.Exception @Before public void setUp) throws Exception i stacknew MyBridgesStack); n1"Able"; n2"Baker"; n3"Charlie"; private void pushAllElements)f stack.push (n1); stack.push (n2); stack.push (n3); eTest public final void visualizeTest) final ByteArrayOutputStream myOut - new ByteArrayOutputStream); System.setOut (new PrintStream(myOut)); pushA1lElements(); stack.visualize) final String standardOutput-myOut.toString); assertTrue(standardoutput.contains ("http://bridges-cs.herokuapp.com/")); * Test push onto an empty stack eTest public final void testPush1) [ stack.push("Rodney Ram"): assertEquals (stack.peek(), "Rodney Ram") * Test push onto a stack with elements eTest public final void testPush2) pushA1lElements(); stack.push("Rodney Ram"): assertEquals (stack.peek(), "Rodney Ram") * Test push onto a full stack Test public final void testPush3) pushA1lElements(); stack.push("Alan Turing"); stack.push( "Ada Lovelace"); stack.push("Adm. Grace Hopper") eTest public final void testPush4) pushA1lElements(); stack.push(""); assertEquals("", stack.peek )) * Test method for pop) an empty stack eTest (expected -EmptyStackException.class) public final void testPop1) f stack.pop O; * Test method for pop) after push eTest public final void testPop2) pushA1lElements(); assertEquals("Charlie", stack.pop)); * Test method for pop() after clear() @Test (expected EmptyStackException.class) public final void testPop3) f pushA1lElements(); stack.clear: stack.pop); * Test peek() before pushing anything eTest (expected -EmptyStackException.class) public final void testPeek1) f stack.peek); * Test peek() after push eTest public final void testPeek2) pushA1lElements(); assertEquals("Charlie", stack.peek)) * Test peek() after push & pop eTest public final void testPeek3) pushA1lElements(); stack.pop); assertEquals( "Baker", stack.peek)) * Test peak after clear @Test (expected EmptyStackException.class) public final void testPeek4) pushA1lElements(); stack.clear: stack.peek); * Test method for isEmpty) initially eTest public final void testIsEmpty1) assertTrue(stack.isEmpty()): * Test method for isEmpty) after push eTest public final void testIsEmpty2) pushA1lElements(); assertFalse(stack.isEmpty)): * Test method for isEmpty) after push & pop eTest public final void testIsEmpty3) pushA1lElements(); stack.pop); assertFalse(stack.isEmptyO); * Test method for isEmpty) after push & pops eTest public final void testIsEmpty4) pushA1lElements(); stack.pop); stack.pop); stack.pop); assertTrue(stack.isEmpty)) * Test method for isEmpty) after clear eTest public final void testIsEmpty5) pushA1lElements(); stack.clear: assertTrue(stack.isEmpty)) * Test method for clear() after initialization eTest public final void testClear10 stack.clear: assertTrue(stack.isEmpty)) * Test method for clear() after pushing eTest public final void testClear2) pushA1lElements(); stack.clear: assertTrue(stack.isEmpty))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

Students also viewed these Databases questions