1.This lab is a minor extension to the previous multi-file project. It adds sorting to the repertoire of tasks that must be performed. The major differences between this and the previous lab are highlighted below.
A file will be specified at the time of this exercise that contains an unknown number of unsorted records. Each record has been written in binary and is constructed according to the following class declaration:
public class Data implements Comparable
{
private String ssn ; // Length = 9
private String fName; // Length = 20
private String mName; // Length = 1
private String lName; // Length = 30
private String addr ; // Length = 40
private String city ; // Length = 20
private String state; // Length = 2
private String zip ; // Length = 9
}
You can use the same Data class as you did in the previous lab. The same is true of the driver . The changes that need to be made are as follows:
i.Since the data in the file is not sorted, you cannot invoke the Arrays.binarySearch static method if the linear search finds the search SSN. You must first sort the Data[] you created from the binary file.
ii.The driver needs to report the time it took to sort the Data[].
iii.The driver needs to report the indices at which it found the search SSN for both the linear and binary search.
iv.Your output should appear as follows. Highlighted sections represent changes in the output when compared to that of the previous lab.
Enter the file you want read - Lab05.bin
Lab05.bin could not be opened.
Do you wish to continue (Y/N)? - y
Enter the file you want read – unsortedData.bin
Preparing to read unsortedData.bin
unsortedData.bin has 1000000 records.
Enter the search SSN (no separators please) - 7Yuv4dxjp
Searching for SSN 7Yu-v4-dxjp
SSN 7Yu-v4-dxjp was not found.
Do you wish to continue with another SSN (Y/N)? - y
Enter the search SSN (no separators please) - C5f*y"WT>
Searching for SSN C5f-*y-"WT>
The key was found in record # 999999.
The linear search required 47 ms to complete.
Arrays.sort required 1507 ms to complete.
After sorting the key was found in record # 375219
The binary search required 0 ms to complete.
SSN = C5f-*y-"WT>
fName = <$5D|W]/0kGBWHL)`d*
mName = d
lName = {|(1!iXRlr+"0R]kk9!rF&ao1,C+Uq
addr = F&sy?^+hl35%b=E:1K"|TL,[F#Mj;J=KTU5/I,E
city = o$_WI_xhNydCT^K@zYq9
state = &U
zip = oY0]-,SCA
Do you wish to continue with another SSN (Y/N)? – n
Do you wish to continue with another file (Y/N)? - n