Question: solve complete question part wise PART IV: CODING (55 POINTS) In what follows, you should complete the java code for the class Stack and MyMain

solve complete question part wise solve complete question part wise PART IV: CODING (55 POINTS) In

what follows, you should complete the java code for the class Stack

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 0) 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 pon(int N) which removes and returns the top N elements of the stack. The elements are returned 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 1 if this stack has a bigger size than other, 0 if they are equal, and -1 otherwise. (10 points) 5- In the main method, create two stacks: s1 and s2 to store integers. Ask the user to enter 2 numbers in s1 and 4 numbers in s2 and scan these numbers. Pop 2 elements from s2. Print the contents of the two stacks. (15 points) public interface Comparable { public int campareda(E o); } import javautite Artaxtist; public class Stack implements Comparable> private ArrayList list = new ArrayList> (); public bretean iematx() { return listuisEmpty(); } public int getSize() { return listasize(); } public String tastring() { return "Stack: "+listutestring(); } // Answer question 1 here (5 pts) // Answer question 2 here (5 pts) // Answer question 3 here (20 pts) // Answer question 4 here (10 pts) } import javautiteArrayist; import javautive Scanner public class MyMaint // Answer question 5 here (15 pts) public static void main(String [largs) { } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!