Question: Here is the code for task 1 and 3 (the interfaces and linked nodes) I need a main method to test my code for task

 Here is the code for task 1 and 3 (the interfaces

Here is the code for task 1 and 3 (the interfaces and linked nodes)

I need a main method to test my code for task 3:

public class PileOfBooks implements BagInterface {

static class Node { T data; Node next;

public Node(T data, Node next) { this.data = data; this.next = next; } }

private Node books; private int numberofbooks;

PileOfBooks() { books = null; numberofbooks = 0; }

public void addBook(T newBook) { books = new Node(newBook, books); numberofbooks++; }

public T removeBook() { if(books == null) { return null; } else { T book = books.data; books = books.next; numberofbooks--; return book; } }

public T topBook() { if(books == null) { return null; } else { return books.data; } }

public boolean isEmpty() { return books == null; }

public void clear() { books = null; numberofbooks = 0; }

public int size() { return numberofbooks; }

public String toString() { String result=""; Node temp = books; while (temp != null) { result += temp.data + " "; temp = temp.next; } return result; }

@Override public int getCurrentSize() { // TODO Auto-generated method stub return 0; }

@Override public boolean add(T newEntry) { // TODO Auto-generated method stub return false; }

@Override public T remove() { // TODO Auto-generated method stub return null; }

@Override public T peek() { // TODO Auto-generated method stub return null; }

}

INTERFACE:

public interface BagInterface { public int getCurrentSize(); // Sees whether this bag is empty public boolean isEmpty(); // Adds new entry to the bag, if possible. public boolean add(T newEntry); // Removes unspecified entry from the bag, public T remove(); public void clear(); public T peek(); }

Task 1: 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 the top of the pile. If you represent books by their titles alone, design a class that you can use to track the books in the pile on your desk. Specify each operation by stating its purpose, by describing its parameters, and by writing a pseudocode version of its header. Then write a Java interface for the pile's methods. Please follow the code examples in our lecture slides to comment your code. resizable array in your implementation. Then write a program that adequately demonstrates your implementation. Task 3: Repeat Task 2, but use a chain of linked nodes instead of an array. Task 4: Using Big Oh notation, indicate the time complexity of each method defined (in Task 2 and Task 3) in the best case and the worst case. Please provide explanations for your answers

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!