This is Java Programming! You need to make a BstMaxHeap.java file. Instructions: Make a file named BstMaxHeap that will implement that implements the Driver.java and MaxHeapInterface.java. The codes are below. If you haven't looked at the code, look at them now. Driver.java: /** A driver that demonstrates the class BstMaxHeap. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public class Driver { public static void main(String[] args) { String jared = "Jared"; String brittany = "Brittany"; String brett = "Brett"; String doug = "Doug"; String megan = "Megan"; String jim = "Jim"; String whitney = "Whitney"; String matt = "Matt"; String regis = "Regis"; MaxHeapInterface aHeap = new BstMaxHeap<>(); aHeap.add(jared); aHeap.add(brittany); aHeap.add(brett); aHeap.add(doug); aHeap.add(megan); aHeap.add(jim); aHeap.add(whitney); aHeap.add(matt); aHeap.add(regis); if (aHeap.isEmpty()) System.out.println("The heap is empty - INCORRECT"); else System.out.println("The heap is not empty; it contains " + aHeap.getSize() + " entries."); System.out.println("The largest entry is " + aHeap.getMax()); System.out.println("\n\nRemoving entries in descending order:"); while (!aHeap.isEmpty()) System.out.println("Removing " + aHeap.removeMax()); System.out.println("\n\nTesting constructor with array parameter:\n"); String[] nameArray = {jared, brittany, brett, doug, megan, jim, whitney, matt, regis}; MaxHeapInterface anotherHeap = new BstMaxHeap<>(nameArray); if (anotherHeap.isEmpty()) System.out.println("The heap is empty - INCORRECT"); else System.out.println("The heap is not empty; it contains " + anotherHeap.getSize() + " entries."); System.out.println("The largest entry is " + anotherHeap.getMax()); System.out.println("\n\nRemoving entries in descending order:"); while (!anotherHeap.isEmpty()) System.out.println("Removing " + anotherHeap.removeMax()); } // end main } // end Driver MaxHeapInterface.java: /** An interface for the ADT maxheap. @author Frank M. Carrano @author Timothy M. Henry @version 5.0 */ public interface MaxHeapInterface> { /** Adds a new entry to this heap. @param newEntry An object to be added. */ public void add(T newEntry); /** Removes and returns the largest item in this heap. @return Either the largest object in the heap or, if the heap is empty before the operation, null. */ public T removeMax(); /** Retrieves the largest item in this heap. @return Either the largest object in the heap or, if the heap is empty, null. */ public T getMax(); /** Detects whether this heap is empty. @return True if the heap is empty, or false otherwise. */ public boolean isEmpty(); /** Gets the size of this heap. @return The number of entries currently in the heap. */ public int getSize(); /** Removes all entries from this heap. */ public void clear(); } // end MaxHeapInterface This is the output we're suppsed to get after we make the BstMaxHeap file: /* The heap is not empty; it contains 9 entries. The largest entry is Whitney Removing entries in descending order: Removing Whitney Removing Regis Removing Megan Removing Matt Removing Jim Removing Jared Removing Doug Removing Brittany Removing Brett Testing constructor with array parameter: The heap is not empty; it contains 9 entries. The largest entry is Whitney Removing entries in descending order: Removing Whitney Removing Regis Removing Megan Removing Matt Removing Jim Removing Jared Removing Doug Removing Brittany */
This is Java Programming! You need to make a BstMaxHeap.java file.
Instructions: Make a file named BstMaxHeap that will implement that implements the Driver.java and MaxHeapInterface.java. The codes are below. If you haven't looked at the code, look at them now.
Driver.java:
/**
A driver that demonstrates the class BstMaxHeap.
@author Frank M. Carrano
@author Timothy M. Henry
@version 5.0
*/
public class Driver
{
public static void main(String[] args)
{
String jared = "Jared";
String brittany = "Brittany";
String brett = "Brett";
String doug = "Doug";
String megan = "Megan";
String jim = "Jim";
String whitney = "Whitney";
String matt = "Matt";
String regis = "Regis";
MaxHeapInterface<String> aHeap = new BstMaxHeap<>();
aHeap.add(jared);
aHeap.add(brittany);
aHeap.add(brett);
aHeap.add(doug);
aHeap.add(megan);
aHeap.add(jim);
aHeap.add(whitney);
aHeap.add(matt);
aHeap.add(regis);
if (aHeap.isEmpty())
System.out.println("The heap is empty - INCORRECT");
else
System.out.println("The heap is not empty; it contains " +
aHeap.getSize() + " entries.");
System.out.println("The largest entry is " + aHeap.getMax());
System.out.println("\n\nRemoving entries in descending order:");
while (!aHeap.isEmpty())
System.out.println("Removing " + aHeap.removeMax());
System.out.println("\n\nTesting constructor with array parameter:\n");
String[] nameArray = {jared, brittany, brett, doug, megan,
jim, whitney, matt, regis};
MaxHeapInterface<String> anotherHeap = new BstMaxHeap<>(nameArray);
if (anotherHeap.isEmpty())
System.out.println("The heap is empty - INCORRECT");
else
System.out.println("The heap is not empty; it contains " +
anotherHeap.getSize() + " entries.");
System.out.println("The largest entry is " + anotherHeap.getMax());
System.out.println("\n\nRemoving entries in descending order:");
while (!anotherHeap.isEmpty())
System.out.println("Removing " + anotherHeap.removeMax());
} // end main
} // end Driver
MaxHeapInterface.java:
/**
An interface for the ADT maxheap.
@author Frank M. Carrano
@author Timothy M. Henry
@version 5.0
*/
public interface MaxHeapInterface<T extends Comparable<? super T>>
{
/** Adds a new entry to this heap.
@param newEntry An object to be added. */
public void add(T newEntry);
/** Removes and returns the largest item in this heap.
@return Either the largest object in the heap or,
if the heap is empty before the operation, null. */
public T removeMax();
/** Retrieves the largest item in this heap.
@return Either the largest object in the heap or,
if the heap is empty, null. */
public T getMax();
/** Detects whether this heap is empty.
@return True if the heap is empty, or false otherwise. */
public boolean isEmpty();
/** Gets the size of this heap.
@return The number of entries currently in the heap. */
public int getSize();
/** Removes all entries from this heap. */
public void clear();
} // end MaxHeapInterface
This is the output we're suppsed to get after we make the BstMaxHeap file:
/*
The heap is not empty; it contains 9 entries.
The largest entry is Whitney
Removing entries in descending order:
Removing Whitney
Removing Regis
Removing Megan
Removing Matt
Removing Jim
Removing Jared
Removing Doug
Removing Brittany
Removing Brett
Testing constructor with array parameter:
The heap is not empty; it contains 9 entries.
The largest entry is Whitney
Removing entries in descending order:
Removing Whitney
Removing Regis
Removing Megan
Removing Matt
Removing Jim
Removing Jared
Removing Doug
Removing Brittany
*/
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 2 images