Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LISTING 5-1 An interface for the ADT stack public interface StackInterface<T> {

ID: 3866147 • Letter: L

Question

LISTING 5-1 An interface for the ADT stack
public interface StackInterface<T>
{
/** Adds a new entry to the top of this stack.
@param newEntry an object to be added to the stack */
public void push(T newEntry);
/** Removes and returns this stack’s top entry.
@return either the object at the top of the stack or, if the
stack is empty before the operation, null */
public T pop();
/** Retrieves this stack’s top entry.
@return either the object at the top of the stack or null if
the stack is empty */
public T peek();
/** Detects whether this stack is empty.
@return true if the stack is empty */
public boolean isEmpty();
/** Removes all entries from this stack */
public void clear();
} // end StackInterface

Now the question is :

1) Repeat Project 1, but instead define a class of stacks that implements the interface StackInterface, as defined in
Listing 5-1 in Chapter 5.

Project 1 is :

LISTING 1-1 A Java interface for a class of bags
/**
An interface that describes the operations of a bag of objects.
@author Frank M. Carrano
*/
public interface BagInterface<T>
{
/** Gets the current number of entries in this bag.
@return the integer number of entries currently in the bag */
public int getCurrentSize();
/** Sees whether this bag is full.
@return true if the bag is full, or false if not */
public boolean isFull();
/** Sees whether this bag is empty.
@return true if the bag is empty, or false if not */
public boolean isEmpty();
/** Adds a new entry to this bag.
@param newEntry the object to be added as a new entry
@return true if the addition is successful, or false if not */
public boolean add(T newEntry);
/** Removes one unspecified entry from this bag, if possible.
@return either the removed entry, if the removal
was successful, or null */
public T remove();
/** Removes one occurrence of a given entry from this bag,
if possible.
@param anEntry the entry to be removed
@return true if the removal was successful, or false if not */
public boolean remove(T anEntry);
/** Removes all entries from this bag. */
public void clear();
/** Counts the number of times a given entry appears in this bag.
@param anEntry the entry to be counted
@return the number of times anEntry appears in the bag */
public int getFrequencyOf(T anEntry);
/** Tests whether this bag contains a given entry.
@param anEntry the entry to locate
@return true if the bag contains anEntry, or false otherwise */

/** Creates an array of all entries that are in this bag.
@return a newly allocated array of all the entries in the bag */
public T[] toArray();
} // end BagInterface

Now the question is : Define a class of bags that implements the interface BagInterface, as defined in Listing 1-1 in Chapter 1. Use an
instance of the class ArrayList to contain a bag’s entries. Then write a program that adequately demonstrates
your new class. Note that you might have to handle exceptions thrown by methods of ArrayList.

can any one give me the code pleaseee

Explanation / Answer

Cannot upload image now. Please provide me an hour. Will upload once server are online. Am running out of time