Question: JavaProgramming VickeryAuction, need some help getting this started. Thanks Winner should be highest bidder, but the price should be second highest bid. Directions: implement class

JavaProgramming VickeryAuction, need some help getting this started. Thanks

Winner should be highest bidder, but the price should be second highest bid.

Directions: implement class Bid in the Auction package.

class Bid will have two fields, price, and bidder, each with getters. The class needs a constructor taking a bidder name and a price. It also needs a static method fromString which takes a string and returns an instance of the class, or throws a NumberFormatException explaining the problem.

Class Bid needs another static method readBids that takes a Scanner instance (for input) and PrintWriter (for output) and reads lines from the scanner, creating a Bid object for each line(using fromString). It will return an array of all the bids read, and print a message (to the PrintWriter) for each problem encountered(essentially, each time it "catch" es an error thrown by fromString.

package Auction;

import java.io.PrintWriter; import java.util.Scanner;

/** * A class to implement an auction using sealed secret bids in which * the winner (highest bidder) pays the second highest bid. * @see https://en.wikipedia.org/wiki/Vickrey_auction */ public class VickreyAuction { public static void main(String[] args) { try (Scanner input = new Scanner(System.in)) { try (PrintWriter pw = new PrintWriter(System.out)) { run(input,pw); } } } public static void run(Scanner input, PrintWriter output) { // TODO: // 1. read bids // 2. check that we have enough bids // 3. figure out the winner and print the price they pay } }

--------Bid class-------------

package Auction;

public class Bid { private String bidder; private double price; public double getPrice() { return price; } public String getBidder() { return bidder; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!