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
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images