• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

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.EmptyStackException;

          public class Stack {

             private ArrayList stack = new ArrayList();

             public void push(Object obj) {
                   // Add obj to the stack.

             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?
  • 2
  • 2
1 Solution
Bob LearnedCommented:
What is your first impression?  What are your thoughts?

dadominator227Author Commented:
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
Bob LearnedCommented:
Pseudo code description of drop-out stack:

A Drop-Out Stack behaves like a stack in every way except that when you create it, you specify its size (n) as a parameter of the constructor.  If you the client using the Drop-Out Stack attempts to push n+1 elements onto the stack then the first element, the one at the bottom of the stack is removed.

Yes, what you have shown should return the current size of the stack, but it will not allow the property to be set.  Is that what you wanted?

dadominator227Author Commented:
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...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now