dadominator227
asked on
Need a little help here
hi.im currently working on another programming assignment form my teacher.heres what we have to do:
Implement a drop-out stack of INTEGER using ArrayList.Write a driver program to test implementation.Name your class DropOut.The methods in your class should be as follows:
public DropOut (int num
public void push (Integer element)
public Integer pop ()
public Integer peek()
public boolean isEmpty()
public boolean isFull ()
public int size
this should print a listing of the stackf rom top to bottom:
public String toString()
okay so this i shwat i have for the implementations in the class DropOut:
import java.util.ArrayList;
import java.util.EmptyStackExcept ion;
public class Stack {
private ArrayList stack = new ArrayList();
public void push(Object obj) {
// Add obj to the stack.
stack.add(obj);
}
public Object pop() {
// Return and remove the top item from
// the stack. Throws an EmptyStackException
// if there are no elements on the stack.
if (stack.isEmpty())
throw new EmptyStackException();
return stack.remove(stack.size()- 1);
}
public boolean isEmpty() {
// Test whether the stack is empty.
return stack.isEmpty();
}
} // end class Stack
is this a drop-out stack and how do i implement public int size() to print out the size of the stack?
Implement a drop-out stack of INTEGER using ArrayList.Write a driver program to test implementation.Name your class DropOut.The methods in your class should be as follows:
public DropOut (int num
public void push (Integer element)
public Integer pop ()
public Integer peek()
public boolean isEmpty()
public boolean isFull ()
public int size
this should print a listing of the stackf rom top to bottom:
public String toString()
okay so this i shwat i have for the implementations in the class DropOut:
import java.util.ArrayList;
import java.util.EmptyStackExcept
public class Stack {
private ArrayList stack = new ArrayList();
public void push(Object obj) {
// Add obj to the stack.
stack.add(obj);
}
public Object pop() {
// Return and remove the top item from
// the stack. Throws an EmptyStackException
// if there are no elements on the stack.
if (stack.isEmpty())
throw new EmptyStackException();
return stack.remove(stack.size()-
}
public boolean isEmpty() {
// Test whether the stack is empty.
return stack.isEmpty();
}
} // end class Stack
is this a drop-out stack and how do i implement public int size() to print out the size of the stack?
ASKER
well i know that a drop-out stack has a limit to what it will hold...as for the size implementation, i was thinking something like this:
public int size()
{
return stack.length
}
would that return the size of the drop-out stack
public int size()
{
return stack.length
}
would that return the size of the drop-out stack
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh i understand on the drop-out stack now...and yes that is what i wanted for the size...ok let me try implementing these and then ill come back with results...thanks...
Bob