(Lab #2) |
Question: I don't really understand what the compareTo method does. I know that it compares the two objects'names and should return -1, 0, or 1 but I don't get how it decideds if one name is greater than the other. Does it have a built in checker for alphabetical order or something? And when you say that the class uses this method for order, does that mean that the number returned by the method is used to place object in alphabetical order? Answer: compareTo really depends on what two things are being compared, on numbers this is the standard <, =, > relationships, on Strings it's alphabetical order... you'll need to decide how to compare two of your objects. Also remember that you'll need to create your own objects, the food class is just an example. Yes, you will use compareTo to created a sorted list.
Question: We are confused by the comments for the insertInOrder method in the LinkedList class. It says it should insert the item after before the first item it finds with a greater value as reported by compareTo(). What does "after before" mean? And what is meant by "greater value"? Should our compareTo() method test if the list is in alphabetical order or something along these lines? Right now, that method returns 0 or 1. Answer: I don't have the code in front of me, but it sounds like that comment didn't communicate very well!
Question: In the instructions for lab for it says that the database should be "interactive", does this mean that we use I/O or can we just use static tests? Answer: This means that it should have a menu or other tool for user interaction -- it should be a "product".
Question: Is the Database class a test driver class? Answer: It could be -- but we really want you to test the components individually with test drivers, as well.
Question: Can our new class similar to "Food.java" have any accessor methods (i.e. getName() )? Answer: Sure!
Question: What does the CompareTo do in the Food.java file? Does it return a 0 or a 1 depending on whether or not they are equal? if so, how does the insertInOrder method in LinkedList.java 'order' the nodes? Also, what does the following mean? Answer: Comparable is an interface, any class that implements Comparable must have this compareTo method which is supposed to give you a way to order things. You do NOT instantiate a Comparable, you instantiate a class that implements the interface. |