THIS ASSIGNMENT IS DUE IN HARDCOPY, HANDWRITTEN OR WORD PROCESSED, TURNED IN IN THE BOX IN 161CN, BY 4PM FRIDAY, APRIL 20th.
These problems are based primarily on Chapters 3, 5 and 6 in your texbook.
For the problems below, you're welcome to write and execute code to explore them. Of course on tests you'll have to be ready to answer questions such as these without the aid of a computer (or your textbook). Also, you may want to refer to any extra Java book(s) you have or the online textbooks or other Java info (the API) in answering the questions.
1. If a string is immutable, explain how it is possible to execute the following statements? What "happens to" the string "abc"?
String s = "abc"; s = s + "def";
2. For a Java variable v of type Vector:
3. Redraw the diagram shown after the following statements are executed. In particular, what is the status of the string "summer" at the end of this sequence of statements?
m = x; x = a; y = b + "s"; // k is passed to a function that doubles all odd element values b = "abc";
4. After reading the following paragraphs, write out four groups of statements for the mythical class Climb (as in a mountain climb or hike) and for each function, corresponding to the specifications for OVERVIEW, REQUIRES, EFFECTS and MODIFIES, statements that correctly capture the content of the description in the paragraphs. Also, comment as to whether the descriptions correspond to any underdetermined behavior, to use your textbook's terminology. You may need to make explicit certain implicit constraints, such as the inappropriateness of having a negative number of items.
"The class Climb is handy for planning various climbs for mountains in its database. You can load just the parts of the DB you need into your laptop and haul it with you wherever you go. Just don't take it in your whitewater raft! And in addition (since you're a CS type) you'll need to build some other code for this class to use it with any convenience. Luckily there's functionality in this class to produce HTML descriptions with refs to the stored images in the right places."
"One of the procedures is alternate(), which when given a Route (produced by getRoute()) will return a vector of alternate Routes. The first argument is a Route, the second the maximum of alternatives wanted and the third, an integer from 1 to 10 for the desired difficulty of the alternate routes. The procedure will limit the alternatives to 5. If alternate routes are few, the procedure may return Routes with alternate starting points or even, occasionally, alternate endpoints, e.g., an easy route not reaching the summit."
"Another procedure is addDetails() which, when given a Route will alter it by adding further details, more images, etc., in the Route argument. It will make no changes to a Route that already has details added."
5. Assuming you have a Vector of Strings, create an Iterator for it and write a simple for loop that uses the Iterator to loop through the elements of the vector, printing them out one per line. Hint: Vector is a Collection type so you don't have to define your own next() and hasNext() methods.
6. Sketch part of an implementation of a ConnectionSet by doing the following:
Go to COM1204 home page
Return to Prof. Futrelle's home page