[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • 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.
                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?
0
dadominator227
Asked:
dadominator227
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
What is your first impression?  What are your thoughts?

Bob
0
 
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
0
 
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?

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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