JAVA LANGUAGE
For this assignment, you will 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 steck: A collection of itens that are inserted * and renoved according to the last-in first-out principle, but with overflow handled by the removal of the least-recently accessed ite 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, or you can modify any of the classes provided in the modules to meet the requirements of a bounded stack. However, you cannot use any of the classes from the Java Collections Framework, (like ArrayList, etc). Just for fun, I do highly recommend trying this assignment with one of more of these classes, but do not turn that in. 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 overflow0: This private method removes the oldest item in the stack. . public boolean isEmptyl: This public method will return true if the stack is empty For testing. let's look at why we need the BoundedStack class Browser History Web browsers commonly allow you to navigate through a "history of web pages which have previously been visited. The mechanism is somewhat like a stack, in that the most recently visited pages are at the top of the history and revisited when the "back" button is pressed However, the history does not really have infinite capacity. In reality, there may exist a fixed limit on the size of the history. The issue arises as to what should happen when the capacity is exhausted and a new item is pushed onto the stack. You will use the BoundedStack class for the browser history that only has room to save 50 pages in its history. When the client visits more pages, it will make room in the history for a new page by throwing away the page which is on the very bottom of the history fi.e., the least recently visited page). When the client wishes to go back to the last visited page, that page will be popped from the top of the history. Maji Game You will also need the BoundedStack class to assist with a larger game that includes characters who battle using magical spells. Because each of the spells has a potency value, the spell with the highest potency wins the battle. Throughout the game, players stack their spells to be used later in a speed battle round up to a maximum of 50 spells. During the game, if a player adds a spell when the stack is full the spell is added to the top of the BoundedStack and the least recently added spell is removed from the bottom. In the speed battle, the last spell to be added to the stack is played first. You will use the BoundedStack class to load one player's spell potency values into the stack, then display the stack in reverse order to simulate the order each spell potency will be used in the speed round. Requirements for the main class: Browser History 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. Create an object of the BoundedStack class for a stack of Doubles for the magi spell potency values. This will be a Double BoundedStack object. Call the push method and pass a Double magic spell value. 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 spell potency values. For this assignment, you will 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 steck: A collection of itens that are inserted * and renoved according to the last-in first-out principle, but with overflow handled by the removal of the least-recently accessed ite 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, or you can modify any of the classes provided in the modules to meet the requirements of a bounded stack. However, you cannot use any of the classes from the Java Collections Framework, (like ArrayList, etc). Just for fun, I do highly recommend trying this assignment with one of more of these classes, but do not turn that in. 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 overflow0: This private method removes the oldest item in the stack. . public boolean isEmptyl: This public method will return true if the stack is empty For testing. let's look at why we need the BoundedStack class Browser History Web browsers commonly allow you to navigate through a "history of web pages which have previously been visited. The mechanism is somewhat like a stack, in that the most recently visited pages are at the top of the history and revisited when the "back" button is pressed However, the history does not really have infinite capacity. In reality, there may exist a fixed limit on the size of the history. The issue arises as to what should happen when the capacity is exhausted and a new item is pushed onto the stack. You will use the BoundedStack class for the browser history that only has room to save 50 pages in its history. When the client visits more pages, it will make room in the history for a new page by throwing away the page which is on the very bottom of the history fi.e., the least recently visited page). When the client wishes to go back to the last visited page, that page will be popped from the top of the history. Maji Game You will also need the BoundedStack class to assist with a larger game that includes characters who battle using magical spells. Because each of the spells has a potency value, the spell with the highest potency wins the battle. Throughout the game, players stack their spells to be used later in a speed battle round up to a maximum of 50 spells. During the game, if a player adds a spell when the stack is full the spell is added to the top of the BoundedStack and the least recently added spell is removed from the bottom. In the speed battle, the last spell to be added to the stack is played first. You will use the BoundedStack class to load one player's spell potency values into the stack, then display the stack in reverse order to simulate the order each spell potency will be used in the speed round. Requirements for the main class: Browser History 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. Create an object of the BoundedStack class for a stack of Doubles for the magi spell potency values. This will be a Double BoundedStack object. Call the push method and pass a Double magic spell value. 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 spell potency values