Question: In Java 1. Add the following methods to the LinkedStack class, and create a test driver for each to show that they work correctly. In

In Java

1. Add the following methods to the LinkedStack class, and create a test driver for each to show that they work correctly. In order to practice your array related coding skills, code each of these methods by accessing the internal variables of the ArrayLinkedStack, not by calling the previously defined public methods of the class.

String toString()creates and returns a string that correctly represents the current stack. Such a method could prove useful for testing and debugging the class and for testing and debugging applications that use the class. Assume each stacked element already provided its own reasonable toString method.

int size()returns a count of how many items are currently on the stack. Do not add any instance variables to the ArrayBoundedStack class in order to implement this method.

void popSome(int count)removes the top count elements from the stack; throws StackUnderflowException if there are less than count elements on the stack.

boolean swapStart()if there are less than two elements on the stack returns false; otherwise it reverses the order of the top two elements on the stack and returns true.

T poptop( )the classic pop operation, if the stack is empty it throws StackUnderflowException; otherwise it both removes and returns the top element of the stack.

2. Use the LinkedStack class to support an application that tracks the status of an online auction. Bidding begins at 1 (dollars, pounds, euros, or whatever) and proceeds in increments of at least 1. If a bid arrives that is less than the current bid, it is discarded. If a bid arrives that is more than the current bid, but less than the maximum bid by the current high bidder, then the current bid for the current high bidder is increased to match it and the new bid is discarded. If a bid arrives that is more than the maximum bid for the current high bidder, then the new bidder becomes the current high bidder, at a bid of one more than the previous high bidders maximum. When the auction is over (the end of the input is reached), a history of the actual bids (the ones not discarded), from high bid to low bid, should be displayed. For example:

New Bid Result High Bidder High Bid Maximum Bid
7 John New high bidder John 1 7
5 Hank High bid increased John 5 7
10 Jill New high bidder Jill 8 10
8 Thad No change Jill 8 10
15 Joey New high bidder Joey 11 15

The bid history for this auction would be

Joey 11
Jill 8
John 5
John 1

Input/output details can be determined by you or your instructor. In any case, as input proceeds the current status of the auction should be displayed. The final output should include the bid history as described above.

//---------------------------------------------------------------------------// LinkedStack.java by Dale/Joyce/Weems Chapter 2//// Implements StackInterface using a linked list to hold the stack elements.//---------------------------------------------------------------------------

package ch02.stacks;

import support.LLNode;

public class LinkedStack implements StackInterface{

protected LLNode top;

// reference to the top of this stack

public LinkedStack()

{

top = null;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets address your question in two parts implementing additional methods in the LinkedStack class and using it for an auction tracking application Ill provide a conceptual approach and code suggestions ... View full answer

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!