Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions