Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Please can anyone do it in Java only.

  1. Add the three classic operations of Queues in the MagazineList.java to make it become a queue.
  2. 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

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago

Question

1. Are my sources credible?

Answered: 1 week ago

Question

3. Are my sources accurate?

Answered: 1 week ago

Question

1. Is it a topic you are interested in and know something about?

Answered: 1 week ago