Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 package ch02.stacks; 2 3 import java.util.Scanner; 4 import java.util.ArrayList; 5 6 7 public class Bid 8 { 9 public String userName; 10 public int

1 package ch02.stacks; 2 3 import java.util.Scanner; 4 import java.util.ArrayList; 5 6 7 public class Bid 8 { 9 public String userName; 10 public int currentBid; 11 public int maxBid; 12 13 public static void main(String[] args) 14 { 15 //Creating object for LinkedStack of type Bid 16 MyExtendsLinkedStack linkedBid = new MyExtendsLinkedStack(); 17 String name; 18 int currBid,mxBid,result; 19 boolean exitLoop = false; 20 Scanner input= new Scanner(System.in); 21 22 do 23 { 24 //Asking user to input user name 25 System.out.println("Please enter the User Name or enter Exit if you need to exit Auction!!."); 26 name = input.nextLine(); 27 28 //If user enters exit, then exit the while loop 29 result = name.compareToIgnoreCase("exit"); 30 if(result ==0) 31 { 32 System.out.println("Exiting Auction!!!"); 33 exitLoop = true; 34 } 35 36 if(exitLoop != true) 37 { 38 //Asking user to input Bid 39 System.out.println("Please enter Bid Value."); 40 currBid = input.nextInt(); 41 input.nextLine(); 42 43 //Creating object for Bid 44 Bid bid = new Bid(); 45 //Assigning the user entered name 46 bid.userName = name; 47 48 //If linkedBid is empty, then setting currentBid value to 1 and pushing into stack 49 if(linkedBid.isEmpty() == true) 50 { 51 bid.currentBid =1; 52 bid.maxBid = currBid; 53 linkedBid.push(bid); 54 } 55 else 56 { 57 bid.currentBid = currBid; 58 Bid existingBid = linkedBid.top(); 59 //Checking if entered bid is greater than the curent bid and less that the current bidder max bid 60 if(bid.currentBid > existingBid.currentBid && bid.currentBidexistingBid.maxBid) 69 { 70 bid.maxBid =bid.currentBid; 71 bid.currentBid = existingBid.maxBid+1; 72 linkedBid.push(bid); 73 } 74 } 75 } 76 }while(!exitLoop); // exiting do while loop, if exit is true 77 78 while(!linkedBid.isEmpty()) { 79 Bid b = linkedBid.poptop(); 80 System.out.println(b.userName + "\t" + b.currentBid); 81 } 82 } 83 84 85 }

THIS CODE WORKS FINE. IT ASK USER TO INPUT NAME & VALUE, BUT I WANT PUT HARD CODE. I DO NOT WANT TO ASK USER ANYTHING.

MY HARD CORD WILL BE

DATA:

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

I WANT TO OUTPUT:

Joey

11

Jill

8

John

5

John

1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions