Question: 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

 In what follows, you should complete the java code for theclass Stack and MyMain based on the below questions. Put your code

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 o) which adds element o to the stack, at first available position in list. (5 points) 2- Write the code of the method popO) 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 poplint 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 compareTo(Stack other) which compares the size of this Stack object with the size of the other Stack. It retums 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:sl and s2 to store integers. Ask the user to enter 2 numbers in sl 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 comparete (E o); } import java.util.Arraydigt; public class Stack implements Comparable>{ private ArrayList list = new ArrayListo(); public boolean Empty() { return listed Emptx(); } public int getSize() ! return listesize(); } public String tostring() { return "Stack: '+list.toString(); } // Answer question 1 here (5 pts) // Answer question 2 here (5 pts) // Answer question 3 here (20 pts) // Answer question 4 here (10 pts) LINDRES jave.usitarrevlist: ineet java.util.Scanner; public class MyMain! // 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!