
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 1
This page cannot be seen from the preview
Don't miss anything!
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):