• Home
• Contact Me
•
Aeries Portal
• Royal High School
• Simi Valley USD

AP Statistics

• Course Calendar
• Chapter Notes
• Practice Tests

AP Comp-Sci
Course Content
• Programs
• Practice Tests

CP Statistics
• Course Calendar
• Chapter Notes
• Practice Tests

Algebra
Geometry

Math Power

AP Computer Science Unit 5 Programs
Manipulating Data: Sorting, Searching and Recursion

WORKING WITH SEARCH ALGORITHMS

 (1)   Write a program that loads an integer array with 25 random integers in the range 1-100. Then ask the user for an integer to search for in the array. The program should use a linear search to find and display the index in the array where that integer first occurs. If the integer does not occur in the array, then a message saying so should be displayed. (2) Write a program to read a list of names from a text file, h:\\txtfiles\\namefile.txt, into an array of type String. You will then prompt the user to enter a name and the program will search the array (using a linear search) and display the index of that name in the array. If the name is not found, then display an appropriate message stating so. Note: all names will need to be converted to uppercase in order for this comparison to be made. Test Data and Output Format The name JOHNSON is in position 5 The name WILSON is not in the array (3) After successfully running the program #1, do a SAVE AS and modify the program so that it will do the search using a binary search algorithm. Recall that this requires that the array first be sorted in ascending order. The output format should be the same as before. (4)  Now modify program #2 (do a SAVE AS) so that it will first sort the list of names before prompting the user for a name to search for. Then use a binary search to search for the name. Again, an error message should be displayed if the name is not found. Test Data and Output Format The name GARCIA is in position 10 The name DOUGLAS is not in the array (5)   Read the file students.txt into an ArrayList of type Student (recall the Student Class from 1st semester). Then allow the user to look up a student by name. Display the entire student record for the found student, or display a message if the student name does not exist in the ArrayList. Use a linear search algorithm.       a. Names that work (try both): Ashley, Eric       b. Names that don't work (try both): Robert, Brianna (6)