This website is preserved for historical and scholarly reference and is no longer actively maintained.
CpSc 210, Section 1
Assignment 6
November 2, 2001
Due: Monday, November 12 at 11:59 p.m.
Assignment: Extend Bailey's QueueArray data structure (pages 145-149)
to include all list methods (pages 99-100), equals, and resize.
Total point value of assignment: 100 points
Not accepted late.
This assignment is to be done INDIVIDUALLY.
Assignment: Design and implement a class, ArrayList as an extension of
Bailey's QueueArray, which must be stored in a file named
ArrayList.java. (20 point deduction for failure to name file
correctly!)
The List interface is given on pages 99-100 of Java Structures. Your
program should include each method in the order in which the methods
are listed in the interface except the elements method.. Your program
must also include equals, toString, and resize methods.
An outline of the code follows. Not all pre/post conditions are listed
here, but they are listed on pages 99-100 and should be included in
your code. A default size is supplied for the constructor in the super class.
import structure.QueueArray;
public class ArrayList extends QueueArray
// implements all list methods except elements
{
private static final int defaultSize = 10;
public ArrayList ( ) // calls constructor of QueueArray
public int size ( )
// post: returns number of elements in list
public boolean isEmpty ( )
// post: returns true iff list has no elements
public void clear ( )
// post: empties list
public void add ( Object value )
// post: value is added to beginning of list (see addToHead)
public void addToHead ( Object value )
// post: value is added to beginning of list
public void addToTail ( Object value )
// post: value is added to end of list
public Object peek ( )
// pre: list is not empty
// post: returns first value in list
public Object tailPeek ( )
// pre: list is not empty
// post: returns last value in list
public Object removeFromHead ( )
// pre: list is not empty
// post: removes first value from the list
public Object removeFromTail ( )
// pre: list is not empty
// post: removes the last value from the list
public boolean contains ( Object value )
// pre: value is not null
// post: returns true iff list contains an object equal to value
public Object remove ( Object value )
// post: removes and returns element equal to value
// otherwise returns null
public String toString ( )
// post: returns a String representation of the list
public boolean equals ( Object other )
// pre: other is not null
// post: returns true if this and other contain the same list
// (same order is implied). Otherwise, returns false
public void resize ( )
// pre: the array holding the list is full
// post: doubles the size of the array holding the list
public static void main ( String [ ] args )
// test methods
{
ArrayList myList = new ArrayList();
// etc.
}
}
You should make use of the code supplied by the super class whenever
doing so does not adversely affect the efficiency of your code.
Since we have not covered the elements() method, you should not
attempt to code the elements method.
Grading Rubric:
10 pts. reasonable attempt to solve problem as assigned
10 pts. also compiles
10 pts. style standards (includes clarity)
The following 70 points are available only for code that compiles
and runs without error. Some considerations are:
comments showing methods not changed
code works correctly
appropriate reuse of code of super class
quality of your test driver
Other requirements:
The first operation of your main program must be to print "CPSC 210", your name, the assignment number, and a brief description of the assignment.
Follow the style standards to be found on your instructor's
web page for CPSC 210.
Submit your program using the handin command. There is a link to
the handin description on the CPSC 210 lab page (www.cs.clemson.edu/~lab210).