Question:
I need help with vectors using Java Programming Language?
gnnogales
2008-09-30 19:28:58 UTC
1. Implement the vector ADT as MyVector class (implements Cloneable) with the following public methods:
a. append(Object element) – appending the element at the end of the vector
b. clear() – make the vector collection empty
c. contains(Object element) – check whether the vector contains the element
d. elementAt(int index) – access the element at the given index
e. indexOf(Object element) – find the index of the element
f. insertAt(int index, Object element) – insert the element at the given index
g. isEmpty() – check whether the vector is empty
h. removeAt(int index) – remove the element at the given index
i. remove(Object element) – remove the element from the vector
j. replace(int index, Object element) – replace the element at the given index with the given element
k. size() – get the number of elements in the current vector
l. ensureCapacity(int minCapacity) – make sure the vector gets at least the given capacity
m. clone() – returns a cloned copy of this vector
n. removeRange(int fromIndex, int toIndex) – removes from this vector all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive
o. toString() – returns a string representation of this vector, containing the String representation of each element
p. reverse() – reverse the elements in this vector
q. merge(MyVector vector2) – add all the elements in vector2 to the end of this vector

2. The MyVector class should be created in the collection package.
3. Your implementation should be a self-expanding vector, similar to the DynamicVector in the textbook or like what we discussed in class.
4. After implementing the MyVector class you will test your MyVector class. To test the MyVector class you will create a Lab03 class under the lab package.

5. In the Lab03 class you will do the following:
a. find out on internet what is the Fibonacci number
b. create a static method named test and do the following in this method
i. create an instance of MyVector
ii. add the first 25 Fibonacci numbers into the vector using Fibonacci function, not manually one by one
iii. print out the vector
iv. reverse all the elements
v. make a clone of the vector
vi. print out the original vector
vii. remove all the elements at any odd index of the original vector
viii. print out the original vector
ix. reverse the cloned vector
x. print out the cloned vector (this vector should still contain 25 in order elements)
xi. merge the cloned vector to the original vector
xii. print out the original vector
Four answers:
John
2008-09-30 20:55:06 UTC
The complete answer would take too long to type or explain, but you can get most of the details from Java's instruction manual for the Vector class



http://java.sun.com/j2se/1.5.0/docs/api/



You will notice in the instruction manual that many of the commands you need to implement are already built into Java's Vector class (routines like elementAt, clear, size, isEmpty, toString, and more). That means you will only need to call those routines from inside your own code.



Good luck!
kaptainfelix
2008-09-30 19:35:37 UTC
who gives a s***



Do the words..

Life

a

Get



mean anything?
2008-09-30 19:31:43 UTC
hrthws
2008-09-30 19:33:33 UTC
vectors? i know in physics it's the degree of a line but idk about java... :O


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...