Reference no: EM132064505
Part 1: Create a new project Lab5Part1. This part is going to be based on Lab4Part1 anduse two one-dimensional arrays with data read in from a file.These arrays will be the TopNumber and TopName arrays from Lab4Part1. However, the data that the arrays read from will be unordered from a new data file, SciFiFantasyYearMix.txt.
You will read in the data from the file just as before. Next print the unordered data from the arrays. Use the same menu printing format as from Lab4Part1, i.e. all the numbers and titles in a table. Sort the data in the arrays using a bubble sort method then print the array data again for the user to choose from. Let the user choose and use linear search to print the user's choice and the associated name.
You must write a method that uses the bubble sort algorithm to sort the numeric array. As you sort the numeric array, you must also sort the names array at the same time. Your bubble sort method should take in the TopNumber and TopNames arrays and the MAXITEMS value as the input parameters. Save this program as Lab5Part1.java and put two test runs in your answers file.
Part 2: Create a new project Lab5Part2. Copy the code from Lab5Part1 into the project. Change the arrays TopName and TopNumber into ArrayLists instead of arrays. Instead of calling your bubble sort array, use the built-in sort mechanism to sort TopNumber. Use the input file SciFiFantasySearchable2.txt to test with. Then test with the file CandySearchable.txt . Save this program as Lab5Part2.java and put the two test runs in your answers file.
2.a) In your Lab5Part2 file, can you sort the TopName array with the TopNumber array? Why or why not? Put your answer in your answer file.
Part 3: Create a new project Lab5Part3. Copy Lab5Part1 into the project.NOTE: use arrays not ArrayLists. Create a new bubble sorting method that sorts the name strings instead of the numbers. Follow the same steps as Lab5Part1 but call the string sorting method instead of the number sorting method. Use the same input files as Lab5Part2 to test. Save this program as Lab5Part3.java and put two test runs in your answers file]
Part 4: Create a new project Lab5Part4. Read in the numeric data from SciFiFantasySearchables2.txt Ask the user to pick a value between 0 and the maximum numeric value from the file and have your program determine if it is in the array.
4.a) Create a new project Lab5Part4a from Lab5Part4. Write a method that takes in the array and the user input and determines if the value is in the array by using linear search. If it is the array, return the index of the array location. If it is not in the array, return -1. Print the location of the user's input value in the unsorted array. Next print the unsorted array values out in a table with 40 rows of 5 values each. Use formatted output to make this table. Call the bubble sort method from Lab5Part1 to sort the array and print the values again. Call the linear search method again to determine where the user's value is in the sorted array and output the location.
4.b) Create a new project Lab5Part4b from Lab5Part4. Write a method that takes in the array and the user input and determines if the value is in the array by using binary search. If it is the array, return the index of the array location. If it is not in the array, return -1. Print the location of the user's input value in the unsorted array. Next print the unsorted array values out in a table with 40 rows of 5 values each. Use formatted output to make this table. Call the bubble sort method from Lab5Part1 to sort the array and print the values again. Call the binary search method again to determine where the user's value is in the sorted array and output the location.
4.c) Did linear search find the value in the unsorted array and the sorted array? Why or why not? Put your answer in your answers file.
4.d) Did binary search find the value in the unsorted array and the sorted array? Why or why not? Put your answer in your answers file.
Extra credit tasks if desired. All extra credit is optional:
XC1) Measure time for the sorting methods in 4a and 4b. Create new project Lab5XC1 that creates two intArrayLists of size 5000 that get the same unsorted values stored in them. Use the first array and call a modified bubble sort method for ArrayLists to sort it and use the second array to call the built-in quick sort method for ArrayLists.
For each method, use the Java Instant class to find the instant before the method is called, then another Instant when the method returns to the caller, then subtract the two and print the value to give a measurement of the run time of the method.
Put your program in a loop that runs the entire process 5 times, i.e. creates 5 unique unsorted arrays. Capture the run times of the methods in a 2D array and after the 5 iterations are done, print a table of the times. Make sure the label the columns and rows of your output table.
XC2) Write a method that implements Quicksort withthe Hoare partition scheme for int arrays. Replace the bubble sort method in Lab5Part4b.java with this quicksort method and test as described.
XC3) Write a program that reads in and stores the data from SciFiFantasySearchable2.txt and then prints the table of unsorted data to an output file. Next, sort the array by the numeric data and print this sorted array to the output file. Finally, sort the array by the name data and print this sorted array to the output file. The output file should end with all three tables of the data in the output file. NOTE: There are many ways to create and write to output files in Java. One of the simplest ways to do this is to connect a File , ex.out.txt, to a PrintStream, ex. outFile, and then set up this PrintStream as the designated output stream with the command System.setOut(outFile);
XC4)Write a program to create an integer array or ArrayListof size 2000 and fill it with random numbers between 0 and 10000 using the Random class or the Math.Random class to generate the values. Ask the user to pick a value between 0 and 10000 and your program will determine if it is in the array. Use linear search first, then sort the array with Java's qsort and search again with binary search.