Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 331 Project #2: Implementing a List using Java.util.Vector, Study Guides, Projects, Research of Data Structures and Algorithms

A project for computer science students in cs 331 where they are required to implement a list using the java.util.vector class. Correspondences between adt list operations and vector methods, and tasks students with declaring a vector, adding items, writing methods to display and replace items, and examining capacity changes. The document also includes instructions for documenting the code.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/18/2009

koofers-user-p5x
koofers-user-p5x 🇺🇸

4

(1)

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 331 Project #2 Sept. 22, 2004
Due at start of class on Wednesday, Sept. 29, 2004
50 points
The class java.util.Vector implements a growable array of objects. (Exercise 19, Page
208, Textbook) Simple correspondences between ADT List operations and
java.util.Vector methods are as below:
ADT List operations java.util.Vector methods
createList() Vector()
Vector(int initialCapacity, int capacityIncrement)
isEmpty() isEmpty()
size() size()
add(index, item) add(int index, Object element)
remove(index) removeElementAt(int index)
removeAll() removeAllElements()
get(index) get(int index)
capacity() Returns the current capacity of this vector.
Write a client class that implements a list by using Vector and completes the following tasks:
(10 points each)
a. Declare a vector using the default constructor. Add 6 items (milk, eggs, butter, apples,
bread, and chicken) to the vector. What do methods size() and capacity() return?
b. Write a method displayList() that prints all items stored in the vector.
c. Write a method replace(aList, i, newItem) that replaces the item in index i
with a new item. Use this method to replace apples by nuts in the list.
d. How many items must be added to the vector to cause the capacity to change? What is
the new capacity?
e. Remove all of the elements from the vector. Does the capacity change? Why do you
think the Vector class behaves this way?
Document your source code according to the following rules (page 37, Textbook):
1. An initial comment for the program that includes
a. Statement of purpose
b. Author and date
c. Description of the program’s input and output
d. Description of how to use the program
e. Assumptions such as the type of data expected
f. Statement of exceptions, that is, what could go wrong
g. Brief description of major classes
2. Initial comments in each class that state its purpose and describe the data contained in the class (constants
and variables)
3. Initial comments in each method that state its purpose, preconditions, postconditions, and methods called.
4. Comments in the body of each method to explain import features of subtle logic.

Partial preview of the text

Download CS 331 Project #2: Implementing a List using Java.util.Vector and more Study Guides, Projects, Research Data Structures and Algorithms in PDF only on Docsity!

CS 331 Project #2 Sept. 22, 2004

Due at start of class on Wednesday, Sept. 29, 2004 50 points

The class java.util.Vector implements a growable array of objects. (Exercise 19, Page 208, Textbook) Simple correspondences between ADT List operations and java.util.Vector methods are as below:

ADT List operations java.util.Vector methods createList() Vector () Vector (int initialCapacity, int capacityIncrement) isEmpty() isEmpty () size() size () add(index, item) add (int index, Object element) remove(index) removeElementAt (int index) removeAll() removeAllElements () get(index) get (int index) capacity () Returns the current capacity of this vector.

Write a client class that implements a list by using Vector and completes the following tasks: (10 points each)

a. Declare a vector using the default constructor. Add 6 items (milk, eggs, butter, apples, bread, and chicken) to the vector. What do methods size() and capacity() return?

b. Write a method displayList() that prints all items stored in the vector.

c. Write a method replace(aList, i, newItem) that replaces the item in index i with a new item. Use this method to replace apples by nuts in the list.

d. How many items must be added to the vector to cause the capacity to change? What is the new capacity?

e. Remove all of the elements from the vector. Does the capacity change? Why do you think the Vector class behaves this way?

Document your source code according to the following rules (page 37, Textbook):

  1. An initial comment for the program that includes a. Statement of purpose b. Author and date c. Description of the program’s input and output d. Description of how to use the program e. Assumptions such as the type of data expected f. Statement of exceptions, that is, what could go wrong g. Brief description of major classes
  2. Initial comments in each class that state its purpose and describe the data contained in the class (constants and variables)
  3. Initial comments in each method that state its purpose, preconditions, postconditions, and methods called.
  4. Comments in the body of each method to explain import features of subtle logic.