BoundedBag

BoundedBag - Program [email protected] Xin Chi Due Date Feb 08 2011 Class Comp 401 Instructor Hedlund Section 001 Pledge I have neither given nor received

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /** * Program 4 * * @author Xin Chi * Due Date Feb. 08, 2011 * * Class Comp 401 Instructor Hedlund * Section 001 * * Pledge: I have neither given nor received unauthorized aid on this * program. (signature on file) * */ /** * the purpose of this class is to create add, remove, and contains method for a boundedBag */ import java.util.Arrays; import java.util.Iterator; public class BoundedBag { // Data members protected int contents; // elements of the BoundedBag. protected int capacity = 4; // size of contents. private int empty = -1; private int NOT_FOUND = -1; private int topPosition; // Index of highest used position in contents. // default constructor-create an empty BoundedBag public BoundedBag() { contents = new int[capacity]; topPosition = empty; } // @Mutator // add theValue to the BoundedBag // @requires size()<4 // @ensures topPostion=topPositon+1 public void add(int theValue) { if (topPosition < capacity - 1) { contents[++topPosition] = theValue; } } // @Observer // determines if the BoundedBag contains theValue // @requires size()>0 // @returns true if theValue is in the BoundedBag...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Page1 / 4

BoundedBag - Program [email protected] Xin Chi Due Date Feb 08 2011 Class Comp 401 Instructor Hedlund Section 001 Pledge I have neither given nor received

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online