Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In PriorityQueue.java, write code for the following new functions: 1. public boolean add ( PriorityQueueNode x ) This function adds a new node x

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In PriorityQueue.java, write code for the following new functions: 1. public boolean add ( PriorityQueueNode x ) This function adds a new node x to the priority queue. The node is added to the heap by comparison of the rating attribute. It involves the "percolate up" process and returns true when finished. 2. public PriorityQueueNode remove() This function removes the minimum element of the priority queue and returns it. It involves a call to percolate Down (int hole ). 3. private void percolate Down (int hole) This function takes the position of the next available hole in the priority queue and uses it to bubble the elements through the heap until the heap property is restored. 4. public void display ( ) This function prints out a formatted tree representation of the priority queue showing only the rating of each node. The output should resemble that of a tree. Tip: you may use the StringBuilder class and the String format () method. Empty nodes in the tree can be replaced with "--". Example output is shown below: - 1 3 5 13 14 15 19 254 240 360 NB! You may assume that each rating is unique i.e. there are no duplicates. Run the PriorityQueue Tester.java file once your code is complete to test that your code works. public class PriorityQueueNode { private String type; private String title; private int releaseYear; private int rating; public PriorityQueueNode () { } } } public PriorityQueueNode (String type, String title, int release Year, int rating) { } } 11 11 this.type = this.title = ""; public String getType () { return type; this.release Year = 0; this.rating = 0; public void setType (String type) { this.type = type; } this.type = type; this.title = title; this.release Year = releaseYear; this.rating = rating; public String getTitle() { return title; } public void setTitle (String title) { this.title = title; public int getRelease Year () { return releaseYear; } public void setRelease Year (int releaseYear) { this.release Year = releaseYear; } public int getRating () { return rating; } public void setRating (int rating) { this.rating = rating; } import java.util.Comparator; import java.util. NoSuchElementException; public class PriorityQueue { /* attributes */ private int currentSize; // Number of elements in heap private PriorityQueueNode [ ] PQ; // The priority queue array private static final int DEFAULT_CAPACITY = 2>>14; private Comparator private void percolate Down (int hole ) // [ 6 marks ] { // insert code here } public void display() // [ 6 marks] { } /* auxiliary methods: you may use the below methods to help you write your code, if necessary */ private int compare (PriorityQueueNode lhs, PriorityQueue Node rhs ) { } // insert code here } if (cmp == null) { } } else { } return ((Comparable) lhs) .compareTo (rhs); public void swapReferences (PriorityQueueNode [] a, int p, int q) return cmp.compare (1hs, rhs); PriorityQueueNode tmp = a[p]; a [p] = a[q]; a [q] = tmp; private void doubleArray ( ) { PriorityQueueNode [] newArray; newArray = new PriorityQueueNode [ PQ.length for (int i = 0; i < PQ.length; i++) newArray[i] = PQ[i]; PQ = newArray; * 2 ]; public PriorityQueueNode element ( ) { } } if (isEmpty()) { throw new NoSuchElementException (); public void clear() { } } return PQ[1]; currentSize = 0; public boolean isEmpty() { return currentSize==0; } // end of file import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class PriorityQueue Tester { public static void main(String[] args) { PriorityQueue pq = new PriorityQueue (); { } try File file = new File("netflix_titles_short.csv"); Scanner token = new Scanner (file); token.nextLine(); while (token.hasNext()) { releaseYear, rating); } String line = token.nextLine(); String tmp[] line.split(";"); String type = tmp[0]; String title = tmp[1]; int release Year = Integer.parseInt (tmp [2]); int rating = Integer.parseInt (tmp [3]); PriorityQueueNode node = new PriorityQueueNode (type, title, pq.add (node); token.close(); = } } catch { (FileNotFoundException e) System.out.println (e.getMessage()); System.exit(0); } /* driver program to test your code: do not modify below*/ System.out.println("What is the size of the PQ?"); System.out.println (pq.getSize()); // [ 1 mark if output is correct ] System.out.println(); tree-representation of the PQ: "); System.out.println("Formatted System.out.println(); pq.display(); // [1 mark if output is correct ] of program-----"); System.out.println(); System.out.println("-end type;title;release_year;movie_rating TV Show; The Chair;2021;33 Movie;Oye Lucky! Lucky Oye!; 2008;41 Movie; Amy Tan: Unintended Memoir;2021;71 Movie;Cook Off;2017;35 TV Show;60 Days In;2019;93 Movie;Little Miss Sumo;2018;39 Movie;People You May Know;2016;60 Movie;Monster Hunter: Legends of the Guild;2021;23 TV Show;Sudden;2013;85 Movie; Before the Flood;2016;86 Movie; Dumplin';2018;3 TV Show;Naomi Osaka;2021;34 Movie; Dream/Killer,2015;48 Movie; The Wind;2019;50 TV Show; 7SEEDS;2020;13 Movie;Pee Mak;2013;76 Movie;Highway;2014;10 Movie;Surat Dari Praha;2016;67 Movie; Cats & Dogs: The Revenge of Kitty Galore;2010;14 Movie Blue Movie; Temporada de Caza;2017;24 Movie; A Perfect Man; 2013;40 TV Show; Ken Burns: The Civil War;1990;58 TV Show; Cheuk Wan-Chi: Two Night Stand;2015;70 Movie;Seabiscuit;2003;46 TV Show;Secreto bien guardado;2019;47 TV Show;Aunty Donna's Big Ol' House of Fun;2020;100 Movie;Terra;2015;79 Movie;The Guns of Navarone;1961;20 Movie; Good People;2014;43 Movie;It's Fine;2012;92 Movie;Manu;2018;8 TV Show; Ken Burns Presents: College Behind Bars: A Film by Lynn Novick and Produced by Sarah Botstein;2019;66 Movie;Chhota Bheem & Krishna: Mayanagari; 2011;25 Movie:Mojave:2015;38 Movie;Accomplice;2021;78 Movie; The Magic School Bus Rides Again In the Zone;2020;30 Movie; Behind the Curve;2018;4 Movie; Bill Burr: You People Are All the Same;2012;15 Painful Fragile;2020;59 TV Show; Fresh Movie; Blue Jay;2016;28 Movie;Jim Gaffigan: Obsessed; 2014;64 Movie;Pup Star: World Tour 2018;95 Movie;Earth and Blood;2020;1 Movie;The Little Mermaid;2018;11 TV Show; Black Spot;2019;56 TV Show; Big Mouth;2020;6 Movie; Patient Seventeen; 2017;88 Movie; Doctor Bello;2013;84 Movie;The Lovebirds;2020;89 Movie;Maza Pati Karodpati;1988;51 Movie;Manorama Six Feet Under;2007;12 Movie;Vegas Baby;2016;22 TV Show; Rainbow Ruby;2016;53 Movie;The Letter Reader;2019;82 Movie;Jatt James Bond;2014;73 Movie;Hazaaron Khwaishein Aisi;2003;27 TV Show;ubat; 2013;55 TV Show; Familiar Wife;2018;91 Movie;Shikari; 1991;68 Movie;Evvarikee Cheppoddu; 2019;63 TV Show; Amend: The Fight for America;2021;42 Movie;The Pelican Brief; 1993;16 TV Show; The War: A Film by Ken Burns and Lynn Novick;2007;37 TV Show;Quarantine Tales;2020;21 TV Show; Club Friday The Series 8;2017;65 Movie; First Match;2018;77 Movie; Lucha: Playing the Impossible;2016;9 TV Show; Life;2018;45 Movie;Manto;2018;74 Movie; The Shadow of Violence;2020;26 Movie;#realityhigh;2017;94 TV Show;Who Killed Malcolm X?;2020;17 Movie;Along Came a Spider;2001;49 Movie; Welcome to New York; 2014;52 TV Show;Love Rain;2012;44 Movie; Enter the Anime;2019;62 Movie;Natsamrat - Asa Nat Hone Nahi;2016;18 Movie;Shakti: The Power;2002;36 Fried & Crispy;2021;80 TV Show; Camp X;2014;98 Movie;El Especial de Alex Fernndez Movie;Paheli;2005;7 TV Show;Mismatched;2020;5 Movie;Either Me Or My Auntie;2006;31 Movie;The 3rd Eye 2;2019;69 Movie; Here Alone;2016;90 TV Show; Bitter Daisies;2018;54 TV Show;I AM A KILLER: RELEASED;2020;19 Movie;5CM; 2012;61 Movie; Harriet the Spy: Blog Wars;2010;83 TV Show; Rhyme Time Town;2021;99 Movie; Mohawk; 2017;72 TV Show;Sugar Rush; 2020;29 Movie; Joan Rivers: Don't Start with Me;2012;32 Movie; The BFG;2016;96 Movie;The Wedding Curse;2006;75 TV Show; Mystery Science Theater 3000: The Return;2018;87 TV Show; Bella and the Bulldogs;2015;97 Movie; Banyuki; 2009;2 Movie;Pulang;2018;81 el Especial;2017;57

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Programming questions

Question

What is a procedural language? What is a nonprocedural language?

Answered: 1 week ago