import java.util.ArrayList;
/**
* A simple model of an auction.
* The auction maintains a list of lots of arbitrary length.
*
* @author David J. Barnes and Michael Kölling.
* @version 2011.07.31
*/
public class Auction
{
// The list of Lots in this auction.
private ArrayList<Lot> lots;
// The number that will be given to the next lot entered
// into this auction.
private int nextLotNumber;
/**
* Create a new auction.
*/
public Auction()
{
lots = new ArrayList<Lot>();
nextLotNumber = 1;
}
/**
* Enter a new lot into the auction.
* @param description A description of the lot.
*/
public void enterLot(String description)
{
lots.add(new Lot(nextLotNumber, description));
nextLotNumber++;
}
/**
* Show the full list of lots in this auction.
*/
public void showLots()
{
for(Lot lot : lots) {
System.out.println(lot.toString());
}
}
/**
* Make a bid for a lot.
* A message is printed indicating whether the bid is
* successful or not.
*
* @param lotNumber The lot being bid for.
* @param bidder The person bidding for the lot.
* @param value The value of the bid.
*/
public void makeABid(int lotNumber, Person bidder, long
value)
{
Lot selectedLot = getLot(lotNumber);
if(selectedLot != null) {
Bid bid = new Bid(bidder, value);
boolean successful = selectedLot.bidFor(bid);
if(successful) {
System.out.println("The bid for lot number " +
lotNumber + " was successful.");
}
else {
// Report which bid is higher.
Bid highestBid = selectedLot.getHighestBid();
System.out.println("Lot number: " + lotNumber +
" already has a bid of: " +
highestBid.getValue());
}
}
}
/**
* Return the lot with the given number. Return null
* if a lot with this number does not exist.
* @param lotNumber The number of the lot to return.
*/
public Lot getLot(int lotNumber)
{
if((lotNumber >= 1) && (lotNumber < nextLotNumber))
{
// The number seems to be reasonable.
Lot selectedLot = lots.get(lotNumber - 1);
// Include a confidence check to be sure we have the
// right lot.
if(selectedLot.getNumber() != lotNumber) {
System.out.println("Internal error: Lot number " +
selectedLot.getNumber() +
" was returned instead of " +
lotNumber);
// Don't return an invalid lot.
selectedLot = null;
}
return selectedLot;
}
else {
System.out.println("Lot number: " + lotNumber +
" does not exist.");
return null;
}
}
}
Lot coding is
/**
* A class to model an item (or set of items) in an
* auction: a lot.
*
* @author David J. Barnes and Michael Kölling.
* @version 2011.07.31
*/
public class Lot
{
// A unique identifying number.
private final int number;
// A description of the lot.
private String description;
// The current highest bid for this lot.
private Bid highestBid;
/**
* Construct a Lot, setting its number and description.
* @param number The lot number.
* @param description A description of this lot.
*/
public Lot(int number, String description)
{
this.number = number;
this.description = description;
this.highestBid = null;
}
/**
* Attempt to bid for this lot. A successful bid
* must have a value higher than any existing bid.
* @param bid A new bid.
* @return true if successful, false otherwise
*/
public boolean bidFor(Bid bid)
{
if(highestBid == null) {
// There is no previous bid.
highestBid = bid;
return true;
}
else if(bid.getValue() > highestBid.getValue()) {
// The bid is better than the previous one.
highestBid = bid;
return true;
}
else {
// The bid is not better.
return false;
}
}
/**
* @return A string representation of this lot's details.
*/
public String toString()
{
String details = number + ": " + description;
if(highestBid != null) {
details += " Bid: " +
highestBid.getValue();
}
else {
details += " (No bid)";
}
return details;
}
/**
* @return The lot's number.
*/
public int getNumber()
{
return number;
}
/**
* @return The lot's description.
*/
public String getDescription()
{
return description;
}
/**
* @return The highest bid for this lot.
* This could be null if there is
* no current bid.
*/
public Bid getHighestBid()
{
return highestBid;
}
}
Please let me know if you have any doubts or you want me to modify
the answer. And if you find this answer useful then don't forget to
rate my answer as thumps up. Thank you! :)
import java.util.ArrayList;
import java.util.Iterator;
public class Auction
{
private ArrayList<Lot> lots;
private int nextLotNumber;
private Auction auction1;
private Lot chindo;
private Lot keyfi;
private Lot taco;
public Auction()
{
lots = new
ArrayList<>();
nextLotNumber = 1;
}
public void createScenario()
{
int n = 1;
Person jack = new
Person("John");
Person jill = new
Person("Bob");
Lot abc = new
Lot((n++), "Used Abc");
Lot def = new Lot((n++),
"Def");
Lot ghijklm = new
Lot((n++), "Ghi Jklm");
auction1.enterLot("abc");
auction1.enterLot("def");
auction1.enterLot("ghijklm");
auction1.makeABid(1,
jack, 569);
auction1.makeABid(3,
jill, 4545);
close();
}
public ArrayList<Lot> getUnsold()
{
ArrayList<Lot>
unsold = new ArrayList<Lot>();
for(Lot lot:
lots){
Bid bid = lot.getHighestBid();
if(bid == null){
unsold.add(lot);
}
}
return unsold;
}
public void close()
{
ArrayList noBid = new
ArrayList<Lot>();
System.out.println("The
results of the auction are as follows:");
System.out.println("-----------------------------------------------------");
for(Lot lot :
lots){
Bid bid = lot.getHighestBid();
if(bid != null){
System.out.println("Item Number: " + lot.getNumber());
System.out.println("Item Description: " +
lot.getDescription());
System.out.println("We have a winner!");
System.out.println("Bidder: " + bid.getBidder());
System.out.println("-----------------------------------------------------");
}
}
System.out.println("The
following items received no bids:");
System.out.println(getUnsold());
}
public void enterLot(String
description)
{
lots.add(new
Lot(nextLotNumber, description));
nextLotNumber++;
}
public void showLots()
{
for(Lot lot : lots)
{
System.out.println(lot.toString());
}
}
public void makeABid(int lotNumber, Person
bidder, long value)
{
Lot selectedLot =
getLot(lotNumber);
if(selectedLot != null)
{
boolean successful = selectedLot.bidFor(new
Bid(bidder,value));
if(successful) {
System.out.println("The bid for lot number " +
lotNumber + " was successful.");
}
else {
Bid highestBid = selectedLot.getHighestBid();
System.out.println("Lot number: " + lotNumber +
" already has a bid of: " +
highestBid.getValue());
}
}
}
public Lot removeLot(int lotToRemove)
{
int index = 0;
int rmvLot =
lotToRemove;
boolean found =
false;
if(lotToRemove >=
lots.size()){
return null;
}
else{
while(index <= lots.size() && index <= (lotToRemove -
1) && found == false){
Lot lot = lots.get(index);
if((lots.get(index) == lots.get(rmvLot -1))){
found = true;
}
else{
index += 1;
}
}
}
return
lots.get(index);
}
public Lot getLot(int lotNumber)
{
if((lotNumber >= 1)
&& (lotNumber < nextLotNumber)) {
return lots.get((lotNumber-1));
}
else {
System.out.println("Lot number: " + lotNumber +
" does not exist.");
return null;
}
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Lot
{
private final int number;
private String description;
private Bid highestBid;
public Lot(int number, String description)
{
this.number =
number;
this.description =
description;
this.highestBid =
null;
}
public boolean bidFor(Bid bid)
{
if(highestBid == null)
{
highestBid = bid;
return true;
}
else if(bid.getValue()
> highestBid.getValue()) {
highestBid = bid;
return true;
}
else {
return false;
}
}
public String toString()
{
String details = number
+ ": " + description;
if(highestBid != null)
{
details += " Bid: " +
highestBid.getValue();
}
else {
details += " (No bid)";
}
return details;
}
public int getNumber()
{
return number;
}
public String getDescription()
{
return
description;
}
public Bid getHighestBid()
{
return highestBid;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Bid
{
private final Person bidder;
private final long value;
public Bid(Person bidder, long value)
{
this.bidder =
bidder;
this.value =
value;
}
public Person getBidder()
{
return bidder;
}
public long getValue()
{
return value;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public class Person
{
private final String name;
public Person(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
}
![Auction [-/ldeaProjects Auction] - .src/Auction.java [Auction] Auction-src Auction e IAuction javaLot java Bid java XPerson,j](http://img.homeworklib.com/images/67b34c5f-78cd-4a73-95cc-a6a9ba2ab293.png?x-oss-process=image/resize,w_560)
Modify the Auction class according to these exercises: 4.48: close method 4.49: getUnsold method 4.51: Rewrite getLot method 4.52: removeLot method For help watch Textbook Video Note 4.2 which sho...
I need help with the last method listed in the problem: Implement a class Grid that stores measurements in a rectangular grid. The grid has a given number of rows and columns, and a description string can be added for any grid location. Supply the following constructor and methods: public Grid(int numRows, int numColumns) public void add(int row, int column, String description) public String getDescription(int row, int column) public ArrayList getDescribedLocations() Here, Location is an inner class that encapsulates the...
In java 8. Modify the averageTopSpeed() method (in the class FormulaOne) using only lambdas and streams and print it to the terminal via the driver class: import java.util.*; public class Racer implements Comparable { private final String name; private final int year; private final int topSpeed; public Racer(String name, int year, int topSpeed){ this.name = name; this.year = year; this.topSpeed = topSpeed; } public String toString(){ return name + "-" + year + ", Top...
Define a toString method in Post and override it in EventPost. EventPost Class: /** * This class stores information about a post in a social network news feed. * The main part of the post consists of events. * Other data, such as author and type of event, are also stored. * * @author Matthieu Bourbeau * @version (1.0) March 12, 2020 */ public class EventPost extends Post { // instance variables - replace the example below with your own...
Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a string s as a parameter and returns true if the title of the string is equal to s. Create the same method for your library material copies. Note that it will need to be abstract in the LibraryMaterialCopy class MY CODE **************************************************************** LibraryCard: import java.util.List; import java.util.ArrayList; import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class LibraryCard { private String id; private String cardholderName; ...
NOTE: Use the Account class codes in the section below these questions. Modify the main method in the CheckingAccountDemo class: Take out all previous code. Declare an object array with 10 accounts. Create a for loop to ask user to input each account’s information (name, account number, and initial balance) from keyboard and then initialize for each account object. Create a while loop to allow one to work on depositing and withdrawing operations on any account till one want to...
How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...
i need help to modify this Tree class to include a method leavesCount that returns the number of leaves in a binary tree. (NOTE: Complete leavesCount and leavesCountHelper methods in the Tree class). I already have the test class. java class TreeNode< T extends Comparable< T > > { TreeNode< T > leftNode; T data; TreeNode< T > rightNode; public TreeNode( T nodeData ) { data = nodeData; leftNode = rightNode = null; } public void insert( T insertValue )...
JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet { /** * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList * containing all the indexes of Strings in arr that match String s. For this method, two Strings, * p and q, match when p.equals(q) returns true or if both of the compared references are null. * * @param s The string...
Need help with this Java. I need help with the "to do" sections.
Theres two parts to this and I added the photos with the entire
question
Lab14 Part 1:
1) change the XXX to a number in the list, and YYY to a
number
// not in the list
2.code a call to linearSearch with the item number
(XXX)
// that is in the list; store the return in the variable
result
3. change both XXX numbers to the...