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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!