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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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)

Magazine.java :

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 : attached the image below

MagazineRack.java:

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);
}
}

public
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 Magazine Node (mag);
MagazineNode current;
if (list== null)
list node;
else
{
current list;
while (current.next != null)
current.next;
current
current.next = node;
}
}
public String toString()
{
String result = "";
MagazineNode current = list;
while (current != null)
{
}
result + current.magazine + "\n";
current current.next;
}
return result;
} /*
// An inner class that represents a node in the magazine list.
// The public variables are accessed by the Magazine List class.
}
class MagazineNode
{
public Magazine magazine;
public MagazineNode next;
//--
// Sets up the node
11.
public Magazine Node (Magazine mag)
{
magazine mag;
next = null;
Transcribed Image Text:public 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 Magazine Node (mag); MagazineNode current; if (list== null) list node; else { current list; while (current.next != null) current.next; current current.next = node; } } public String toString() { String result = ""; MagazineNode current = list; while (current != null) { } result + current.magazine + "\n"; current current.next; } return result; } /* // An inner class that represents a node in the magazine list. // The public variables are accessed by the Magazine List class. } class MagazineNode { public Magazine magazine; public MagazineNode next; //-- // Sets up the node 11. public Magazine Node (Magazine mag) { magazine mag; next = null;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Threads in linked list
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education