Question
a) Implement a Java Stack named BookStack for a Book class given the following interface StackADT and Book class codes: // StackADT interface public interface
a) Implement a Java Stack named BookStack for a Book class given the following interface StackADT and Book class codes:
// StackADT
interface public interface StackADT {
boolean isEmpty (); int length ();
void push (Book b); Book pop (); }
// Book class public class Book { private String isbn; private String title; private double price; public Book(String isbn, String title, double price) {
this.isbn = isbn;
this.title = title;
this.price = price;
} public String getIsbn() { return isbn; } public double getPrice() { return price; } public String getTitle() { return title; } } 9 The BookStack class:
- should provide an implementation of a LIFO system, storing Book objects in a fixed Java array size of 5 of Book objects.
- have a zero-argument constructor that initializes the necessary attributes such as creating an empty array and setting the size to zero.
- Has a length() method that returns the number of elements in the stack. - Has an push() method to place a Book object onto the stack. If the stack is full, it should disallow any more items on the stack.
- Has a pop() method that returns a Book object if successful or null if the stack is empty.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started