I'm trying to create a list stack that implements some interface called SomeList
The list stack should only use stack with no links. the itnerface has a number of methods that I would like to implement.

So for SomeList I have something like

public interface SomeList<T>{public void plus(T something);public E takeout(int somewhere); and so on}

For the generic ListStack I have something like
public class ListStack<T> implements SomeList<T>{
Stack<T> stack1=new Stack<E>();

//constructor
public LinkStack(){
stack1=new Stack<T>();
}

//method
public void plus(T somethig){
this.push();}

.
.
.
}

In the method above (plus(T something)) I get an error on push. Eclipse tells me to create a new method called push.

I want a new stack to be created whenever someone creates a stack list object
Any ideas on how to do this?

Recommended Answers

All 13 Replies

In the method above (plus(T something)) I get an error on push. Eclipse tells me to create a new method called push.

That's clear enough. What's your question?

I want a new stack to be created whenever someone creates a stack list object

Isn't that what line 9 in your constructor does?

How do I fix the method problem?

If there is supposed to be a push() method tghen write it. If that's wrong then fix line 14.
I'm not sure what your problem is with this... what is line 14 intended to do?

It's supposed to add the item passed to the add method onto the stack created when LinkedStack is created

OK, so you need to look at the API doc for Stack to find the correct syntax for pushing an item onto the stack. (hint: the item to be pushed should be in there somnewhere)

Since I cannot edit the article

this.push(something);}

Getting closer...
now what is the object (list) onto which "something" is being pushed?

the stack that's created in the constructor when a LinkedStack object is created

So when you say this.push(something); you are trying to call the push method of "this" - the current object (the current ListStack). You want to invoke the push method of your Stack (the one you created in the constructor)

Exactly

Surely by now you know how to call a method using a variable to specify which object you are calling it on. It's one the very first things you learn in Java (rememberSystem.out.println(...) ?)

This is going no where.

This is so frutrating! I know that you know how to do this, but it seems I'm going to have to break my own rules and spell out the code...

to push an item something onto a Stack stack1 the code is

stack1.push(something);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.