|
|
|
|
![]() ![]() |
Jan 20 2008, 02:39 AM
Post
#1
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 643 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
Ok at my Uni they teach you OOP with java, They used to do with C++ i believe but swiched to java because its easier to teach people OOP with java apparently.
Anyway I've been working on some exercises with java (book is 'objects first with java'). I've got this one exercise which I cant understand. QUOTE Exercise 4.29 Rewrite getLot so that it does not rely on a lot with a particular number being stored at index (number - 1) in the collection. For instance, if lot number 2 has been removed, then lot number 3 will have been moved from index 2 to index 1, and all higher lot numbers will also have been moved one index position. You may assume that lots are always stored increasing order of their lot number. this is the existing getLot method CODE /** * 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; } } I dont get what the exercise is asking me to do This post has been edited by sonesay: Jan 20 2008, 02:39 AM |
|
|
|
Jan 20 2008, 03:41 AM
Post
#2
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 13 Joined: 20-January 08 Member No.: 56,526 |
Does it say anywhere above that what lots exactly is? I don't see where it came from or what it is.
The only thing I can gather from the question is that they want you to make lots a dynamic list rather than a static array so that you can remove and add in the middle without having to shift everything after it. Though, I don't see anywhere in the getLot method where they are actually shifting anything... so I don't see how they want you to change it. Sorry I couldn't be of more help. I hate it when I have questions like those to do. |
|
|
|
Jan 20 2008, 03:46 AM
Post
#3
|
|
|
|||[ n00b King ]||| ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 643 Joined: 20-June 07 From: Auckland Member No.: 45,102 |
Lots is like an item being sold at the auction house. sorry I didnt want to paste the entire code/classes its too long
anyway heres the sulotion I found in PDF format. it only covers chapter 4 of the book. if anyone else needs it. http://www.eden.rutgers.edu/~muresan/202_O.../solutions4.pdf |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 26th July 2008 - 06:39 AM |