Imagine a pile of books on your desk. Each book is so large and heavy that you can remove only the top one from the pile. You cannot remove a book from under another one. Likewise, you cannot add a book beneath another one. You can add another book to the pile only by placing it on top of the pile. If you represent booka by thier titles alone, the "PileInterface.java" interface attached can be used to track the books in the pile on your desk.  Define a class "PilesOfBooks.java" that implements this interface using a chain of linked nodes. Then, write a program that demonstrates your implementation (i.e. PilesOfBookDemo.java) to prompt the user for various book titles and thoroughly tests all the methods in the PileOfBooks.java.class. public interface PileInterface { /** Adds a new book to the top of this pile. @param newBook An object to be added to the pile. */ public void add(T newBook); /** Removes and returns this pile's top book. @return Either the book at the top of the pile or, if the pile is empty before the operation, null. */ public T remove(); /** Retrieves this pile's top book. @return Either the book at the top of the pile or null if the pile is empty. */ public T getTopBook(); /** Detects whether this pile is empty. @return True if the pile is empty. */ public boolean isEmpty(); /** Removes all books from this pile. */ public void clear(); } // end PileInterface

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

Imagine a pile of books on your desk. Each book is so large and heavy that you can remove only the top one from the pile. You cannot remove a book from under another one. Likewise, you cannot add a book beneath another one. You can add another book to the pile only by placing it on top of the pile.

If you represent booka by thier titles alone, the "PileInterface.java" interface attached can be used to track the books in the pile on your desk.  Define a class "PilesOfBooks.java" that implements this interface using a chain of linked nodes. Then, write a program that demonstrates your implementation (i.e. PilesOfBookDemo.java) to prompt the user for various book titles and thoroughly tests all the methods in the PileOfBooks.java.class.

public interface PileInterface<T>
{
/** Adds a new book to the top of this pile.
@param newBook An object to be added to the pile. */
public void add(T newBook);

/** Removes and returns this pile's top book.
@return Either the book at the top of the pile or, if the
pile is empty before the operation, null. */
public T remove();

/** Retrieves this pile's top book.
@return Either the book at the top of the pile or null if
the pile is empty. */
public T getTopBook();

/** Detects whether this pile is empty.
@return True if the pile is empty. */
public boolean isEmpty();

/** Removes all books from this pile. */
public void clear();
} // end PileInterface

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
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