Need a little help here

Posted on 2005-04-06
Last Modified: 2012-05-05 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?
Question by:dadominator227
    LVL 96

    Expert Comment

    by:Bob Learned
    What is your first impression?  What are your thoughts?


    Author Comment

    well i know that a drop-out stack has a limit to what it will 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
    LVL 96

    Accepted Solution

    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?


    Author Comment

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

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Report events not being triggered 8 67
    withoutTen challenge 14 69
    Fix45 challenge 15 67
    wordappend challenge 8 54
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    This is about my first experience with programming Arduino.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now