Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the inventoryNew.txt as input file to build a Max-Heap (java PriorityQueue).

ID: 3810538 • Letter: U

Question

Use the inventoryNew.txt as input file to build a Max-Heap (java PriorityQueue). The order of the priority queue is the reverse order of part number. At the end, print the Max-Heap in iterator order and then print the same Max-Heap in priority queue order.
Download Inventory.java and inventoryNew.txt

inventory.java

//********************************************************************
// Inventory.java   
//
//********************************************************************

public class Inventory
{
protected String PartNo;
protected String Model;
protected String Description;
protected Double ListPrice;

//-----------------------------------------------------------------
// Constructor: Sets up this inventory using the specified
// information.
//-----------------------------------------------------------------
public Inventory() {

}

public String GetPartNo()
{
return PartNo;
  
}
public void SetInventory (String ePartNo, String eModel, String eDescription, Double eListPrice)
{
PartNo = ePartNo;
Model = eModel;
Description = eDescription;
ListPrice = eListPrice;
}


//-----------------------------------------------------------------
// Returns a string including the basic inventory information.
//-----------------------------------------------------------------
public String toString()
{
String result = null;
if (PartNo != null)
{
result = "Part Number: " + PartNo + " ";
result += "Model: " + Model + " ";
result += "List Price: "+ Double.toString(ListPrice) + " ";
result += "Description: " + Description + " ";
}
return result;
}

//-----------------------------------------------------------------
//
//-----------------------------------------------------------------

public String getPartNo()
{
return PartNo;

}

public String getModel()
{
return Model;
}

public String getDesc()
{
return Description;
  
}

public double getListPrice()
{
return ListPrice;
}

}

inventoryNew.txt

GT12C1068A,YUKON XL,07-14 GMC YUKON XL RT Front fender brace Lower Bracket Hinge,24.00
NI27E1251B,ALTIMA SDN,13-15 NISSAN ALTIMA SDN RT Front fender liner From 10-12 (CAPA),63.00
NI23H1297A,ALTIMA SDN,13-15 NISSAN ALTIMA SDN LT Front fender liner From 10-12 (CAPA),48.00
CV15F1067A,SILVERADO 1500 (NEW),07-13 CHEVY SILVERADO 1500 LT Front fender brace Lower Bracket Hinge,23.00
HY07E1288A,SONATA,15-16 HYUNDAI SONATA Front bumper cover 2.4L Std Type w/o Park Assist prime (CAPA),326.00
CV20B1225B,SILVERADO 1500 HYBRID,09-13 CHEVY SILVERADO 1500 HYBRID LT Front fender brace Lower Bracket Hinge,23.00
CV39A1251A,AVALANCHE,07-13 CHEVY AVALANCHE RT Front fender brace Lower Bracket Hinge,24.00
CV39A1250A,SUBURBAN,07-14 CHEVY SUBURBAN RT Front fender brace Lower Bracket Hinge,24.00
AC12C1250AQ,MDX,07-13 ACURA MDX LT Front fender liner (CAPA),68.00
AC12C1251AQ,MDX,07-13 ACURA MDX RT Front fender liner (CAPA),68.00

Explanation / Answer

import java.util.Comparator;

import java.util.PriorityQueue;

public MaxHeap_PQ()

{

public int compare(Integer o1, Integer o2)

{

public int extractMax()

{

public int getSize()

{

public void print()

{

public static void main(String[] args)

{

import java.util.Comparator;

import java.util.PriorityQueue;

public class MaxHeap_PQ { PriorityQueue<Integer> pq;

public MaxHeap_PQ()

{

pq = new PriorityQueue<Integer>(10, new Comparator<Integer>() { @Override

public int compare(Integer o1, Integer o2)

{

return o2 - o1; } }; } public void insert(int[] x) { for (int i = 0; i < x.length; i++) { pq.offer(x[i]); } }

public int extractMax()

{

return pq.poll(); } public void display() { System.out.println(pq); }

public int getSize()

{

return pq.size(); }

public void print()

{

System.out.println(pq); }

public static void main(String[] args)

{

int[] arrA = { 1, 6, 2, 9, 4, 3, 8 }; MaxHeap_PQ i = new MaxHeap_PQ(); i.insert(arrA); i.print(); System.out.println("Max Elmnt in the Priority Queue: " + i.extractMax()); System.out.println("Max Elmnt in the Priority Queue: " + i.extractMax()); System.out.println("Max Elmnt in the Priority Queue: " + i.extractMax()); System.out.println("Priority Queue Size: " + i.getSize()); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote