Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Java Exercise Help, I need help to understand this question
sonesay
post 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 sad.gif any help apprecaited

This post has been edited by sonesay: Jan 20 2008, 02:39 AM
Go to the top of the page
 
+Quote Post
Jephthah
post 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. sad.gif
Go to the top of the page
 
+Quote Post
sonesay
post 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 sad.gif. I think I've found the solution now on the net. The website for the book is so cheap they got text based discussions lol. I hate those its so hard to read and find info.

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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Java editor(72)
  2. Auto Run Java Program(11)
  3. Java Script Drop Down Menu With Css(2)
  4. [help] Java Script: Window.open(8)
  5. How To Create Java Button Or Frame(12)
  6. Java Basic Program Guidance(6)
  7. Java Helpdesk(8)
  8. What's The Relationship Between Javascript And Java(5)
  9. Problem With Java Script Popup Form(1)
  10. The Power Of Java(14)
  11. Jsp Or Java Chat Script Like Mig33(4)
  12. I Need Help With Java(3)
  13. Text Image Java Problem(1)
  14. Help Deploying Java(0)
  15. Which Is The Best Java Web Framework?(0)
  1. Helpful Registry Edit For Java Programmers(2)
  2. Java Iterator Help(2)
  3. Beginning Java(10)
  4. Java In A High School Software Design Course(5)
  5. Java Part 1(2)
  6. Circular Movment/animation In Java?(6)
  7. Java Applet Query(1)
  8. Java Or C++(2)
  9. Java Vs Javascript(11)
  10. Java Object[][] Help(2)
  11. Learn Java Programming Language Online Step By Step(0)
  12. Java Game(2)
  13. Call Pdf995 From Java(0)


 



- Lo-Fi Version Time is now: 26th July 2008 - 06:39 AM