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

Work programming exercise 11.10, page 447. Please follow the specifications give

ID: 3885946 • Letter: W

Question

Work programming exercise 11.10, page 447. Please follow the specifications given in the problem statement. Write a separate test program following the specification in the problem statement.

11.10 (Implement MyStack using inheritance) In Listing 11.10, MyStack is implemented using composition. Define a new stack class that extends ArrayList. Draw the UML diagram for the classes and then implement MyStack. Write a test program that prompts the user to enter five strings and displays them in reverse order.

Explanation / Answer

import java.util.ArrayList;

public class NewStack extends ArrayList<object>

{

public object getsize()

{

return get(size()-1);

}

public object pop()

{

object s=get(size()-1);

remove (size()-1);

return s;

}

public object push(object s)

{

add(s);

}

public String toString()

{

return "stack " + super.toString();

}

}

public class stack1()

{

public static void main(String arg[])

{

NewStack st=new NewStack();

System.out.println("Enter Strings");

for (int i=0;i<5;i++)

st.push(input,next());

System.out.println("Reverse Strings");

while (st.size()>0)

{

System.out.println(st.pop());

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote