[Solved]Java Port Hueneme Receives Shipment Cars Car Distinct Id Consists 3 Letters Upper Case Rep Q37203773
in Java
Port Hueneme receives a shipment of cars. Each car has a distinct id that consists of 3 letters in upper case (represented by a String), followed by a space, followed by 14 digits (represented by a long). As the cars are being unloaded from the ship their IDs are recorded and placed in sorted order in a file. The file is sent to the dealer. The cars are driven to the dealership by designated drivers and arrive at the destination in random order. The car IDs are recorded at the dealership. Your task is to compare the files and detect if they contain the same elements utilizing hashing technique with O(n) complexity.
To check if they havethe same elements with hash table, consider the followingalgorithm:
- Construct the hash table with array A elementsas keys:
- while inserting the elements, keep track of frequency for eachnumber in the key’s value
- After constructing the hash table for A’s elements, iterateover the array B:
- for each occurrence of B’s element in the hash table, decrementthe corresponding key’s value
- At the end, check whether all counters are zero or not
- if all counters are zero, then both arrays are the sameotherwise they are different
- Think and implement also the scenarios where the checkingprocess should stop earlier
Using the abovealgorithm as a guide, design an algorithm to check if two filescontain the same elements (see UML diagram).
CarID class mustimplement Comparable interface in order to put CarID objects into aTreeSet. Also:
- Set DEFAULT_CHARACTER_SEQUENCE to “???”
- Set DEFAULT_NUMERIC_SEQUENCE to 100000000000000L
- Please note that the equals method accepts Object as theinput
- For the hashCode method use the following formula:
G * (hash code forthis.characterSequence) + (integer result of foldingthis.numericSequence)
where G is 31
CheckInventory classhas main method implemented. You need to implement the remainingmethods:
- set DEAFULT_CAPACITY to 5
- generateContentAndSaveToRandomFile method: generates the carIDs randomly and saves them in a TreeSet<CarID> to ensurethat they are distinct. At the same time when it is known that theyare distinct writes them into randomFile.txt.
- saveSortedContentToSortedFile method: writes the content of theTreeSet<CarID> returned by the above method to thesortedFile.txt.
- createCorruptedFile method: also writes the content of theTreeSet<CarID> to a file, but this time the name of the fileis corruptedFile.txt. The method randomly decides which elementsshould be skipped in order to produce a file that will not have thesame elements as the original file.
- compareInventory method: performs the comparison usingoptimized version of the above algorithm:
- throws InputMismatchException in case duplicates in the sentfile are found
public class CheckInventory{ // TODO Project 2 Part1 – implement CardID class // TODO Project 2 Part1 – implement CheckInventory class // uncomment main when the class CardID and // the skeleton for this class are in place// public static void main(String[] args)// {// String receivedFile = “randomFile.txt”;// String sentFile = “sortedFile.txt”;// String corruptedFile = “corruptedFile.txt”;// CheckInventory checker = new CheckInventory();//// try// {// System.out.println(“How many CarIDs to generate?”);// Scanner keyboard = new Scanner(System.in);// int amount = keyboard.nextInt();// TreeSet<CarID> sortedSet = checker.generateContentAndSaveToRandomFile(amount, receivedFile);// checker.saveSortedContentToSortedFile(sortedSet, sentFile);// checker.createCorruptedFile(sortedSet, corruptedFile);// System.out.println(“n*** Checking if “” + sentFile + “” and “” + receivedFile + “” have the same elements ***”);// boolean same = checker.compareInventory(receivedFile, sentFile);// System.out.println(“–> the elements in files “” + receivedFile// + “” and “” + sentFile// + ” are ” + (same ? “” : “NOT “) + “the same”);////// System.out.println(“n*** Checking if “” + sentFile + “” and “” + corruptedFile + “” have the same elements ***”);// checker.createHashedDictionary();// same = checker.compareInventory(sentFile, corruptedFile);// System.out.println(“–> the elements in files “” + corruptedFile// + “” and “” + sentFile// + ” are ” + (same ? “” : “NOT “) + “the same”);//// } catch (IOException ioe)// {// System.out.println(“There was an error in reading or opening the file: “);// System.out.println(ioe.getMessage());// } catch (InputMismatchException ime)// {// System.out.println(ime.getMessage());// }// System.out.println(“nBye!”);// } // end main
Expert Answer
Answer to in Java Port Hueneme receives a shipment of cars. Each car has a distinct id that consists of 3 letters in upper case (r… . . .
OR

