Please help me for the following questions: A word file containing description o
ID: 638847 • Letter: P
Question
Please help me for the following questions:
A word file containing description of the program, code in java, screen shots of test runs, a discussion of any difficulties encountered or new ideas.
#1
Answer the following questions about the Balanced class:
a. Is there any functional difference between the class being instantiated in the following two ways?
Balanced bal = new Balanced ("abc", "xyz") ; Balanced bal = new Balanced ("cab", "zxy") ;
b. Is there any functional difference between the class being instantiated in the following two ways?
Balanced bal = new Balanced ("abc", "xyz") ; Balanced bal = new Balanced ("abc", "zxy") ;
c. Is there any functional difference between the class being instantiated in the following two ways?
Balanced bal = new Balanced ("abc", "xyz") ; Balanced bal = new Balanced ("xyz", "abc") ;
d. Which type is pushed onto the stack? A char? An int? An Integer? Explain.
e. Under which circumstances is the first operation performed on the stack (not counting the new operation) the top operation?
f. What happens if the string s, which is passed to the test method, is an empty string?
#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 bidder
Explanation / Answer
// Algorithm
// Assumption - Bidder object - { bid value, bidder name }
LinkedStack onlineAuctionTracker; // Top of the stack represents the current high bidder
LLObjectNode maxBidder; // Maximum bid of the current high bidder
onlineAuctionTracker.push(defaultBid); // Create a linked stack with one object (first bid with a value '1' and no name)
maxBidder = defaultBid;
while(end of input){
ifnewBidVal <= onlineAuctionTracker.top().getBidVal()) {
continue; //This bid is discarded
}
else if((onlineAuctionTracker.top().getBidVal() < newBidVal) && newBidVal <= maxBidder.getInfo().getBidVal())){
// create newHighBid object - bid value - newBidVal, bidder - (onlineAuctionTracker.top().getBidder())
onlineAuctionTracker.push(newHighBid);
}
else if(newBidVal > maxBidder.getInfo().getBidVal()){
// Update the current high bidder object - top of the linkedStack
if(1 == onlineAuctionTracker.sizels()){
newHighBidder.bidVal = onlineAuctionTracker.top.getBidVal();
}
else{
newHighBidder.bidVal = maxBidder.getInfo().getBidVal() + 1;
}
newHighBidder.bidder = newBidder;
onlineAuctionTracker.top.setInfo(newHighBidder);
newHighBidder.bidVal = newBidVal;
maxBidder.setInfo(newHighBidder);
}
}
toString method has to be defined for bidder class to get the bidder and bid value format.
To get the desired output, toString method implemented for LinkedStack can be used with proper formatting to print all the elements in the onlineAuctionTracker
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.