Question
I NEED THIS IN 15 MINUTES Please can anyone do it in Java only. Add the three classic operations of Queues in the MagazineList.java to
I NEED THIS IN 15 MINUTES
Please can anyone do it in Java only.
- Add the three classic operations of Queues in the MagazineList.java to make it become a queue.
- Add testing code in MagazineRack.java to test your code. (You do not need to modify Magazine.java). Here are the codes below. Please help I feel lost.
Magazine.java code below
---------------------------
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 Code Below
----------------------------------
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; } } 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. //***************************************************************** } class MagazineNode { public Magazine magazine; public MagazineNode next; //-------------------------------------------------------------- // Sets up the node //--------------------------------------------------------------
public MagazineNode(Magazine mag) { magazine = mag; next = null; } }
----------------------------------
MagazineRack.java code below
-----------------------------------
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); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started