Daje kod klasy:
import java.util.ArrayList;
import java.util.Iterator;
/**
-
A simple model of an auction.
-
The auction maintains a list of lots of arbitrary length.
-
@Author David J. Barnes and Michael Kolling.
-
@version 2003.10.06
*/
public class Auction
{
// The list of Lots in this auction.
private ArrayList 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();
nextLotNumber = 1;
}
/**- Enter a new lot into the auction.
- Lots can only by entered into the auction by an
- Auction object.
- @param description A description of the lot.
*/
public void getUnsold()
{
}
public void enterLot(String description)
{
lots.add(new Lot(nextLotNumber, description));
nextLotNumber++;
}/**
- Show the full list of lots in this auction.
*/
public void showLots()
{
Iterator it = lots.iterator();
while(it.hasNext()) {
Lot lot = (Lot) it.next();
System.out.println(lot.toString());
}
}
/**
- Bid for a lot.
- A message indicating whether the bid is successful or not
- is printed.
- @param number The lot number being bid for.
- @param bidder The person bidding for the lot.
- @param value The value of the bid.
*/
public void bidFor(int lotNumber, Person bidder, long value)
{
Lot selectedLot = getLot(lotNumber);
if(selectedLot != null) {
if(selectedLot.bidFor(new Bid(bidder, value))) {
System.out.println("The bid for lot number " +
lotNumber + " was successful.");
}
else {
System.out.println("Lot number: " + lotNumber +
" already has a bid of: " +
selectedLot.getHighestBid().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 = (Lot) 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: " +
"Wrong lot returned. " +
"Number: " + lotNumber);
}
return selectedLot;
}
else {
System.out.println("Lot number: " + lotNumber +
" does not exist.");
return null;
}
}
}
- Create a new auction.
public void showLots()
{
Iterator it = lots.iterator();
while(it.hasNext()) {
Lot lot = (Lot) it.next();
System.out.println(lot.toString());
}
co to jest to "Lot lot = (Lot) " (Lot) - wiem , że to jest casting i pokazanie o który obiekt nam chodzi, ale o co biega z tym Lot lot na początku? Może ktoś ma jakiś artykuł albo zna odpowiedź. Proszę o pomoc i dziękuje za odpowiedź.