humanize-my-essay-free

(Solved) : Checkinventory Application Java Part 1 Implement Checkinventory Application Port Hueneme Q37222888 . . .

  • I. CheckInventory Application in java

Buy ready-to-submit essays. No Plagiarism Guarantee!

Note: All our papers are written by real people, not generated by AI.

Part 1 – Implement CheckInventoryApplication

Check your essay before you submit. See exactly what your professor sees.

See your AI and plagiarism results before your instructor does.Get the exact same report your professor uses. Trusted by 50,000+ students worldwide.

Port Hueneme receives a shipment of cars. Each car has adistinct id that consists of 3 letters in upper case (representedby a String), followed by a space, followed by 14 digits(represented by a long). As the cars are being unloaded from theship their IDs are recorded and placed in sorted order in a file.The file is sent to the dealer. The cars are driven to thedealership by designated drivers and arrive at the destination inrandom order. The car IDs are recorded at the dealership. Your taskis to compare the files and detect if they contain the sameelements utilizing hashing technique with O(n) complexity.

For example, the following two arrays have the same set ofelements (notice that duplicates are allowed):

A = {2,5,6,8,10,2,2}

B = {2,5,5,8,10,5,6}

To check if they have the same elements with hash table,consider the following algorithm:

  1. Construct the hash table with array A elementsas keys:
    • while inserting the elements, keep track of frequency for eachnumber in the key’s value
  2. 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
  3. 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
  4. Think and implement also the scenarios where the checkingprocess should stop earlier

Your task

Using the above algorithm as a guide, design an algorithm tocheck if two files contain the same elements (see UML diagram).

CarID class must implement Comparable interface in order to putCarID objects into a TreeSet. 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 for this.characterSequence) + (integer result offolding this.numericSequence)

where G is 31

CheckInventory class has main method implemented. You need toimplement the remaining methods:

  • set DEAFULT_CAPACITY to 5
  • generateContentAndSaveToRandomFile method: generates the carIDs randomly and saves them in a TreeSet 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 returned by the above method to thesortedFile.txt.
  • createCorruptedFile method: also writes the content of theTreeSet 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

Utilize PrintWriter to write to a text file; utilize Scanner toread from a file.

The following shows the content of a sample randomFile.txt, Iused Random generator with the seed of 101:

IMPLEMENT CODE import java.util.*;import java.io.*; 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 sortedSet = checker.generateContentAndSaveToRandomFile(amount, receivedFile);// checker.saveSortedContentToSortedFile(sortedSet, sentFile);// checker.createCorruptedFile(sortedSet, corruptedFile);// System.out.println(“*** 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(“*** 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(“Bye!”);// } // end main}

SampleRun:

How many CarIDs togenerate?

5

*** Checking if”sortedFile.txt” and “randomFile.txt” have the same elements***

The content of thehash table after file randomFile.txt was processed:

The size of hash tableis: 11

0     null

1     null

2      KEY: CarID{YCL26173488024166}  VALUE: 1

3      KEY: CarID{IKT79165731364363}  VALUE: 1

4      KEY: CarID{PNN75573168975558}  VALUE: 1

5      KEY: CarID{PFJ61745334134984}  VALUE: 1

6     null

7     null

8     null

9      KEY: CarID{SZD67926802656931}  VALUE: 1

10    null

The content of thehash table after file sortedFile.txt was processed:

The size of hash tableis: 11

0     null

1     null

2      notIn

3      notIn

4      notIn

5      notIn

6     null

7     null

8     null

9      notIn

10    null

–> the elements infiles “randomFile.txt” and “sortedFile.txt are the same

*** Checking if”sortedFile.txt” and “corruptedFile.txt” have the same elements***

The content of thehash table after file sortedFile.txt was processed:

The size of hash tableis: 11

0     null

1     null

2      KEY: CarID{YCL26173488024166}  VALUE: 1

3      KEY: CarID{PNN75573168975558}  VALUE: 1

4      KEY: CarID{IKT79165731364363}  VALUE: 1

5      KEY: CarID{PFJ61745334134984}  VALUE: 1

6     null

7     null

8     null

9      KEY: CarID{SZD67926802656931}  VALUE: 1

10    null

The content of thehash table after file corruptedFile.txt was processed:

The size of hash tableis: 11

0     null

1     null

2      notIn

3      KEY: CarID{PNN75573168975558}  VALUE: 1

4      KEY: CarID{IKT79165731364363}  VALUE: 1

5      KEY: CarID{PFJ61745334134984}  VALUE: 1

6     null

7     null

8     null

9      KEY: CarID{SZD67926802656931}  VALUE: 1

10    null

–> the elements infiles “corruptedFile.txt” and “sortedFile.txt are NOT the same

Bye!

Process finished withexit code 0

Expert Answer


I lOVE this Professional essay writing website. This is perhaps the fifth time I am placing an order with them, and they have not failed me not once! My previous essays and research papers were of excellent quality, as always. With this essay writing website, you can order essays, coursework, projects, discussion, article critique, case study, term papers, research papers, research proposal, capstone project, reaction paper, movie review, speech/presentation, book report/review, annotated bibliography, and more.

Post your homework questions and get original answers from qualified tutors!

PLACE YOUR ORDER

Share your love