Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
CSIS 10B Assignment 3 Vectors Due: next Wed In Class Demo (0 points): 1) Design and Implementation of Vector class – add, get, set remove, copy, equals, ensureCapacity 2) Hangman using Vector class 3) Word Frequency 4) L-system 5) Installing bailey.jar in BlueJ and Eclipse Assignment (10 points) Do either Basic or Advanced. Read Bailey Chapter 3. Also read the self check problems and regular problems on pages 64/65, as well as the answers on pages 442 and 457. Basic—Lab3 VectorPlus Develop your own extension of Bailey's Vector class (Bailey's is referred to as structure5.Vector) that supports the following methods. Call your new class VectorPlus. (Exercises in file VectorPlusTester.java) 1) setSize(int size) -- explicitly sets the size of the vector. a) pre: size <= current size of vector b) post: elementCount is set to size c) data cells from size to end of array ElementData have been set to null 2) insert(int index, Object o) -- inserts Object o into the vector at index. Same as add(int index, Object o), just for practice. a) pre: 0 <= index <= size() b) post: inserts new value in vector with desired index, c) after first moving elements from index to size()-1 to right 3) delete(int index) -- deletes Object at index in the vector. Same as remove(int index), just for practice. a) pre: 0 <= where && where < size() b) post: indicated element is removed by shifting elements from index+1 to size()-1 to left 4) indexOf(Object o) –returns the location (cell number) in the vector that contains Object o (or -1 if Object o is not in the vector). a) pre: none? b) post: index of first Object in array that equals Object o is returned, or -1 5) fill(int lb, int ub, Object o) -- fills the subvector from lb to ub inclusive with Object o a) pre: 0<= lb <= ub < size() b) post: indices from lb to ub (inclusive) are set to Object o 6) swap(int firstpos, int secondpos) -- swaps the elements at the two positions. a) pre: 0<= firstpos < size(), ditto for secondpos b) post: array values at index firstpos and secondpos have been exchanged 7) reverse() –reverses the data in the vector For each of these methods make sure you verify the preconditions with assert prior to running the method. Test your methods using the program VectorPlusTester. 8) Finally, write a small application that loads the entire file words.txt into a VectorPlus object. You can either a) Visit/retrieve each word in the list using a for loop and the vector get method. If the word starts with ‘a’, delete the word from its current location and reinsert the word at 0. If the word starts with ‘s’ delete and reinsert at the end of the list. Print the list to verify. OR b) Use a nested set of for loops along with get and swap methods to sort the words according to length using a BubbleSort algorithm (check the pseudocode here) Advanced: Lab3 Silver Dollar Game If you would like a more difficult challenge, try the game discussed on Bailey p67.