InClassExer2 - CS116 InClassExercise 2 Due:00 p.m on...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS116--- InClassExercise # 2 Due: June 16 10:00 p.m. on Blackboard Objectives: Work with vectors. Show that different data types can be saved in the same vector object. Work with selection sort and binary search algorithms. In this exercise you are going to modify the files you obtained from Lab 2 Task 2. Therefore you may want to start by downloading the files: Vehicles.txt ,,,, You can use the above java files as guideline to create the new java source code files requested below: 1. Rename the class ArrayOfVehicles to a new class with the name of ArrayandVectorOfVehicles. 2. In addition to the existing method arrayV add a new method called vectorV. In method vectorV maintain the same objects using the same values in the constructor of the Vehicle class by reading the text file (as done in the arrayV version). The only difference is that instead of storing the Vehicle objects into an array , store them into a vector. Return the vector with the Vehicle objects. Everything else stays the same as in arrayV. 3. The method selectionSort remains unchanged (still returning a an array of Vehicles). 4. Add a method called binarySearch. The method takes as argument an array of Vehicle types that has been sorted first, and a search key value. It returns an int data type that represents the index that the key was found to be stored, or the value -1 if the key value was not found. The key that we are going to search the 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
array of Vehicles is the value of the velocity attribute of the Vehicle class. See slide 12 of Lecture5.ppt for the sample program. You need to provide modifications to that sample so that the search key is the velocity attribute. Figure out where the changes are needed or ask questions. First of all notice that the array to be passed to this method as argument is an array of Vehicle types! 5. The package for this class stays the same as in the previous version (that is folder1.folder2.folder3). Compile this class (after you have recompiled all the other required classes). Remember that you have to compile using a DOS window and the command as an example: javac –d . Disregard a message like the one below from the compiler: Note: uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 10

InClassExer2 - CS116 InClassExercise 2 Due:00 p.m on...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online