Question: Create a package called heapSort in your 2420 class exercises folder. It should include the following four classes: DeliveryType // enum Mail MailTestClient // provided

Create a package called heapSort in your 2420 class exercises folder.

It should include the following four classes:

  • DeliveryType // enum
  • Mail
  • MailTestClient // provided
  • DemoHeap

The code should use only your own code, code from Algs4, Comparable, and class Arrays

Enum DeliveryType: It includes no fields nor methods, only the following five enum constants: GROUND, AIR, PRIORITY, TWO_DAY, and ONE_DAY

Note that enums are Comparable. That means they have already a compareTo method. The order of enums depends on the order in which the enum constants are declared. http://www.java2s.com/Tutorials/Java/Enum/Java_Enum_compareTo.htm (Links to an external site.)Links to an external site.

Class Mail: Implement class Mail based on the UML class diagram below. In order to generate a random number use the method uniform from class StdRandom.

Accessibility score: Low Click to improve

The mailCode should be a 5 letter code that consists of all upper-case letters. (This is not quite how the US Postal Service works, but it is a good programming practice)

The parameterized constructor initializes the fields based on the arguments provided (no input validation necessary)

The parameterless constructor initializes the fields with a random type and a random mailcode (5 random upper-case letters)

The toString method should return a string of the following format: {mailcode}({type}) Where {mailcode} and {type} are substituted by the corresponding field values.

The compareTo method compares two mail objects first based on the type. If the type is the same the mail objects are compared based on the mailCode.

Once you are done implementing the enum DeliveryType and the class Mail you can test your code using MailTestClient. Notice how the elements are sorted by type first and within the type by the mail code. MailTestClient.javaCreate a package called heapSort in your 2420 class exercises folder. It

Original array allMail: YTWEW(AIR) ASDFF(GROUND) ASDFG(AIR) UIOPY(TWO_DAY) ASDFG(ONE_DAY) ZXCVB(GROUND) AAABB(GROUND) IUYTR(AIR) SKDIU(TWO_DAY) PQOWI(PRIORITY) Sorted array allMail: AAABB(GROUND) ASDFF(GROUND) ZXCVB(GROUND) ASDFG(AIR) IUYTR(AIR) YTWEW(AIR) PQOWI(PRIORITY) SKDIU(TWO_DAY) UIOPY(TWO_DAY) ASDFG(ONE_DAY)

Class DemoHeap: In this class we'll sort Mail objects. However, rather than using Sedgewick's class Heap, which includes a sort method, we'll use a heap (MinPQ) and remove the elements one by one. Includes a main method in class DemoHeap. It should do the following: Create a MinPQ and fill it with 25 randomly generated Mail objects.

Print "Elements in the priority queue:" Then list all elements of the priority queue without changing the heap (without removing them)

Print "Remove elements one by one from the priority queue:" This time remove all the elements of the priority queue one by one, and as you remove them print them.

I also need help with this one aw well

I can't seem to get it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!