Question

Object Oriented analysis Implement a Stack using List by inheritance. The implementation shall be in both...

Object Oriented analysis

Implement a Stack using List by inheritance. The implementation shall be in both UML and Java Code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.ArrayList;
import java.util.List;

public class ListStack {

    private List<String> data;

    public ListStack() {
        data = new ArrayList<>();
    }

    public void push(String s) {
        data.add(s);
    }
    
    public String top() {
        return data.get(data.size()-1);
    }
    
    public String pop() {
        return data.remove(data.size()-1);
    }
    
    public int size() {
        return data.size();
    }
    
    public boolean isEmpty() {
        return data.isEmpty();
    }
}
Add a comment
Know the answer?
Add Answer to:
Object Oriented analysis Implement a Stack using List by inheritance. The implementation shall be in both...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT