9:02 AM Tue 16 Feb 93% TOO to PART IV: CODING (55 POINTS) In what follows, you should complete the java code for the class Stack and MyMain based on the below questions. Put your code inside the java code given below. 1. Write the code of the method push(E a) which adds element o to the stack, at first available position in list. (5 points) 2. Write the code of the method pop() which removes and returns the element on top of the stack, the last element in list. (5 points) 3. Write the code of the method pop(int n) which removes and returns the top N elements of the stack. The clements are retumed in an ArrayList. In case the stack has less than N elements only those elements are removed and returned. (20 points) 4- Write the code of the method compareToStack
other) which compares the size of this Stack object with the size of the other Stack. It returns I if this stack has a bigger size than other, if they are equal, and otherwise (10 points) 5. In the main method, create two stacks: st and s2 to store integers. Ask the user to enter 20 numbers in stand 14 numbers in s2 and scan these numbers. Pop 2 clements from s2. Print the contents of the two stacks (15 points) public interface Comparable public int compareTo(E o); } import java.util.ArrayList; public class Stack implements Comparable>{ private ArrayList list = new ArrayList>(); public boolean is Empty return list.isEmpty(); > public int getSize() { return list.size(): > public String toString() { return "Stack: +list.toString(); > Il Answer question 1 here (5 pts) Page 6 of 7 9:02 AM Tue 16 Feb 93% TO Il Answer question 2 here (5 pts) Il Answer question 3 here (20 pts) Il Answer question 4 here (10 pts) import java.util.ArrayList; import java.util.Scanner; public class MyMain Il Answer question 5 here (15 pts) public static void main(String args) { Page 7 of 7