Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Name 3. Below is a flawed implementation of the stack ADT. Exploit the flaw by f

ID: 3913925 • Letter: N

Question

Name 3. Below is a flawed implementation of the stack ADT. Exploit the flaw by filling in the main method below so that it prints "Success" by causing BadintegerStack to produce a NullPointerException. 1 public class BadIntegerStack( public class NodeO public Integer value; public Node prev; public Node(Integer v, Node p) value v; prev p 1e public Node top; 12 13 public boolean isEmptyO return top = null; 14 15 16 17 public void push(Integer num) top new Node(num, top)) 19 20 21 public Integer popo 23 24 25 Integer ans top.value; top = top, prev; return ans; 26 public Integer peek ) return top.value; 27 28 29 public static void main(Stringl] args)

Explanation / Answer

BadIntergerStack s = new BadIntegerStack();

//To catch this exception we are using try catch to get success as output.

try{

s.pop(); //Pop element from empty stack will cause nullpointer Exception

}

catch(NullPointerException e){

System.out.println("Success");  

}