Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in JAVA, create a generic class called BoundedStack. The implementation of a BoundedStack is very similar to the implementation given for a Stack. However in

in JAVA, create a generic class called BoundedStack. The implementation of a BoundedStack is very similar to the implementation given for a Stack. However in the case when the capacity is exhausted, a call to push will result in the placement of the new item at the expense of the loss of the least recently accessed item.

/*A bounded stack: A collection of items that are inserted * and removed according to the last-in first-out principle, but with * overflow handled by the removal of the least-recently accessed item. 

For this project you will create a generic BoundedStack class that will be used by the main method for two different data types: String and Double. An object of the BoundedStack class declared as a String BoundedStack will be used for a browser back button. Another object of the BoundedStack class, this one declared as a Double BoundedStack, will be used to get spell potency values for a maji game.

You can create your own BoundedStack class from scratch using a linked list or array implementation, .You cannot use any of the classes from the Java Collections Framework, (like ArrayList, etc).

Important Note: I will ask you to redo the assignment if you use a Stack class that does not meet the requirements of a bounded stack that handles overflow over 50 items, or if you implement your BoundedStack with a class from the Java Collections Framework.

Requirements for the generic BoundedStack class:

  • This class must be named BoundedStack and must be a generic class.
  • This class must have a private data member that is either an array or the head of a linked list. Include the node class as a nested class if you are implementing the BoundedStack with a linked list.
  • A constructor method is required.
  • public void push(E item): This public method adds the generic item to the top of the stack that is limited to 50 objects. If the stack is full, the overflow method is called.
  • public E pop(): This public method removes the generic item from the top of the stack and returns it.
  • private void overflow(): This private method removes the oldest item in the stack.
  • public boolean isEmpty(): This public method will return true if the stack is empty.
  • Requirements for the main class:

  • Create an object of the BoundedStack class for a browser back button. This will be a String BoundedStack object.
  • Call the push method and pass a string: either a web page url or ip address. Repeat the method call in a loop 51 times to test the overflow.
  • Call the pop method until the BoundedStack is empty and display the return value each time. This should display 50 web page urls or ip addresses.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Fundamentals

Authors: Itzik Ben Gan

4th Edition

0138102104, 978-0138102104

More Books

Students also viewed these Databases questions