.. (לתיקייה המכילה) | ||
In Question 1, I can imitatate an "if" decision using a "while" loop. Is it legal? | |
No. The loop is only allowed for iterating over the digits of the number. |
You said that arrays of Strings are not allowed. So, I was thinking of defining a new class, X, which will have a String field. Then my program will use an array of X objects. Is it legal? | |
No. The main point is that your code will be able to take different actions for different digits, not just return a predefined value. For example, we want that for digits 1, 2, 7, 8 the program will write something to a file, whereas for the digit 6 we would like to play a short .mp3 file |
In question 3, is it possible that null will represent the empty list? | |
No, the empty() method will not work on a null reference:Seq s = null;
|
Are there any complexity requirements regarding the operations on Seq objects? | |
As stated in question 3, Seq should be as close as possible to ML's int list. Thus, all the operations listed in question 3 should run in constant time: O(1) |
The assignment is based on Tutorial 3. Does this include slides that were not shown in class? | |
Yes. |
You said that all Seq operations should have an O(1) time complexity. I think this is a mistake, since each time you create a new list you actually apply a deep copy on an existing list. Thus, you need at least O(n) time to complete the operation (The same thing goes for extracting a tail from a given list). | |
You have a flaw in your argument. There is a way to supply an ML-like behvaior in O(1) time |
Regarding class Seq: Should we provide other operations other than the ones listed in the assignment (for example: printing, sorting, deleting an item)? | |
No |
In question 3, I don't understand the meaning of: "create a new list by adding an integer to the head of an existing list". Can you give an example? | |
Suppose that s0 is intialized with an empty list.Seq s1 = s0.add(9); // s1 is [9]
|
You said in the FAQ we can't use an array of Class X, where Class X has a string field. | |
Basically, the answer is No: As said in one of the FAQs, the issue here is being able to take different actions for different digits, without using inheritance. For example: print something to the screen for digits 0-4, where for digits 5-9 the program will show a message box. However, you can use such a "do_action" method if you find a way to customize its behavior without using inheritance. |
The tutorial about objects in Java/C#, says that the combination "static final" in Java means "run-time constant", static final Y y = new Y(); } | |
Well, as was said in class "compile-time constant" may not be the best name, when speaking about objects rather than primitives. In Java, a "static final" field means the following two properties hold for the field: (a) The field is static. i.e.: There is only one such field and it is shared among all instance of the class (b) the field is final. i.e.: The field is assigned (initialized) only once. After initialization the field cannot change its value. So, (a) + (b) imply that the field is initialized before the first time the class is used. So, as far as the instances of this class are concerend, static final fields are initialized before any of the instnaces was created (thus the term "compile-time constant" was chosen) |
How should Seq behave if the code invokes getHead() or getTail() on the empty list? | |
You can assume this never happens. However, it is possible (as stated above) to invoke isEmpty() on the empty list. |
Should we document the code? | |
No. Don't document anything (in this assignment) |
is implementing an interface allowed (we defined an interface with only a Print method and wrote 20 classes, one for each behaviour that implement this interface)? | |
As stated in the assignment, all methods must be concrete (i.e.: non virtual) and no overriding of methods is allowed. |