Hi im learning java through blue j and im having trouble doing an exercise if anyone can help that would be great.
the question is:
Rewrite the getLot method so it doesn't rely on a lot with a particular number being stored at index (number -1) in the collection.You may assume that lots are always stored in increasing order of their lot number.
The method is written ass :
-
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;
-
}
-
-
Any help would be much appreciated again