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

Modify the MagazineRack program presented below by adding delete and insert oper

ID: 3657734 • Letter: M

Question

Modify the MagazineRack program presented below by adding delete and insert operations into the MagazineList class. Have the Magazine class implement the Comparable interface, and base the processing of the insert method on calls to the compareTo method in the Magazine class that determines whether one Magazine title comes before another alphabetically. In the driver, exercise various insertion and deletion operations. Print the list of magazines when complete: public class MagazineRack { public static void main (String[] args) { MagazineList rack = new MagazineList(); rack.add (new Magazine("Time")); rack.add (new Magazine("Woodworking Today")); rack.add (new Magazine("Communications of the ACM")); rack.add (new Magazine("House and Garden")); rack.add (new Magazine("GQ")); System.out.println (rack); } } public class MagazineList { private MagazineNode list; //---------------------------------------------------------------- // Sets up an initially empty list of magazines. //---------------------------------------------------------------- public MagazineList() { list = null; } //---------------------------------------------------------------- // Creates a new MagazineNode object and adds it to the end of // the linked list. //---------------------------------------------------------------- public void add (Magazine mag) { MagazineNode node = new MagazineNode (mag); MagazineNode current; if (list == null) list = node; else { current = list; while (current.next != null) current = current.next; current.next = node; } } //---------------------------------------------------------------- // Returns this list of magazines as a string. //---------------------------------------------------------------- public String toString () { String result = ""; MagazineNode current = list; while (current != null) { result += current.magazine + " "; current = current.next; } return result; } //***************************************************************** // An inner class that represents a node in the magazine list. // The public variables are accessed by the MagazineList class. //***************************************************************** private class MagazineNode { public Magazine magazine; public MagazineNode next; //-------------------------------------------------------------- // Sets up the node //-------------------------------------------------------------- public MagazineNode (Magazine mag) { magazine = mag; next = null; } } } public class Magazine { private String title; //----------------------------------------------------------------- // Sets up the new magazine with its title. //----------------------------------------------------------------- public Magazine (String newTitle) { title = newTitle; } //----------------------------------------------------------------- // Returns this magazine as a string. //----------------------------------------------------------------- public String toString ()

Explanation / Answer

//******************************************************************** This is a full fledged code you required........................ //******************************************************************** public class Magazine { private String title; //----------------------------------------------------------------- // Sets up the new magazine with its title. //----------------------------------------------------------------- public Magazine (String newTitle) { title = newTitle; } //----------------------------------------------------------------- // Returns this magazine as a string. //----------------------------------------------------------------- public String toString () { return title; } } //******************************************************************* // MagazineList.java Author: Lewis/Loftus // // Represents a collection of magazines. //******************************************************************* public class MagazineList { private MagazineNode list; //---------------------------------------------------------------- // Sets up an initially empty list of magazines. //---------------------------------------------------------------- public MagazineList() { list = null; } //---------------------------------------------------------------- // Creates a new MagazineNode object and adds it to the end of // the linked list. //---------------------------------------------------------------- public void add (Magazine mag) { MagazineNode node = new MagazineNode (mag); MagazineNode current; if (list == null) list = node; else { current = list; while (current.next != null) current = current.next; current.next = node; } } //---------------------------------------------------------------- // Returns this list of magazines as a string. //---------------------------------------------------------------- public String toString () { String result = ""; MagazineNode current = list; while (current != null) { result += current.magazine + " "; current = current.next; } return result; } //***************************************************************** // An inner class that represents a node in the magazine list. // The public variables are accessed by the MagazineList class. //***************************************************************** private class MagazineNode { public Magazine magazine; public MagazineNode next; //-------------------------------------------------------------- // Sets up the node //-------------------------------------------------------------- public MagazineNode (Magazine mag) { magazine = mag; next = null; } } } //******************************************************************* // MagazineRack.java Author: Lewis/Loftus // // Driver to exercise the MagazineList collection. //******************************************************************* public class MagazineRack { //---------------------------------------------------------------- // Creates a MagazineList object, adds several magazines to the // list, then prints it. //---------------------------------------------------------------- public static void main (String[] args) { MagazineList rack = new MagazineList(); rack.add (new Magazine("Time")); rack.add (new Magazine("Woodworking Today")); rack.add (new Magazine("Communications of the ACM")); rack.add (new Magazine("House and Garden")); rack.add (new Magazine("GQ")); System.out.println (rack); } } Question: Modify the magazine rack program (from the lecture notes) by adding delete and insert operations into the magazine rack class. The insert method should be based on a compareTo() method in the Magazine class that determines if one magazine title comes before another alphabetically. In the main method, exercise various insertion and deletion operations. Print the magazine rack when complete. Use the code below for your main method: //***************************************************** ************** // MagazineRack.java Author: Lewis/Loftus // // Driver to exercise the MagazineList collection. //***************************************************** ************** public class MagazineRack { //-------------------------------------------------- -------------- // Creates a MagazineList object, adds several magazines to the // list, then prints it. //-------------------------------------------------- -------------- public static void main (String[] args) { MagazineList rack = new MagazineList(); rack.insert (new Magazine("F Title") ); rack.insert (new Magazine("D Title")); rack.insert (new Magazine("G Title")); rack.insert (new Magazine("A Title")); rack.insert (new Magazine("E Title")); rack.insert (new Magazine("H Title")); System.out.println( "After inserts: " + rack ); rack.delete (new Magazine("A Title")); rack.delete (new Magazine("H Title")); rack.delete (new Magazine("G Title")); rack.delete (new Magazine("E Title")); System.out.println( "After deletes: " + rack ); rack.insert (new Magazine("A Title")); rack.insert (new Magazine("E Title")); rack.insert (new Magazine("H Title")); rack.insert (new Magazine("G Title")); System.out.println( "After 2nd inserts: " + rack ); } }

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