homework2 - 15-121 FALL 2009 (Reid-Miller)HOMEWORK 2* - due...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-121 FALL 2009 (Reid-Miller)HOMEWORK 2* - due Saturday, Sep 12 by 11:59PMElectronic handin for this assignment will be available SaturdayPROBLEMS (10 pts)For each of the following problems, write up your answers in a plain-text (ASCII) file. Do not use Word (.doc) or Rich Text Format (.rtf).You should write any code answers without the aid of a compiler to practice solving written problems on paper. After you are satified with your answer, you may test it on the computer, if you wish. Remember, you will not have use of a computer during your written exams. Using the phone directory program discussed in class to answer problems 1-4.1. (2 pts) Modify the lookupEntrymethod so that if the name is found in the phone directory, it is moved to the last used position in the directory array, shifting all subsequent entries up one position. (NOTE: The last used position is not necessarily the last cell of the array.) 2. (1 pt) If we start with an empty phone directory and add 130 phone entries and then remove 70 phone entries, how large is the phone directory array? Explain. 3. (1 pt) In the removeEntry method, why can't we just set the array cell that contains the reference to the matching entry to null and subtract one from numEntries? Explain how this will cause the application to malfunction. 4. (2 pts) Suppose we want to add a new option to the application that allows us to find out how many phone numbers are stored in the phone directory. Show the new code that is needed and the code that needs to be changed to add this new functionality. For each addition or change, indicate which class it occurs in. 5. (1 pt) What is the advantage of using a Java interfaceto specify the behavior of a class rather than just implementing the behavior as a classdirectly? 6. (1.5 pts) What is the difference between a checked exception and an unchecked exception? Which type of exception does the compiler force us to deal with in our code? Give an example of each from the examples shown in class. 7. (1.5 pts) Consider the following simple linear search method that returns the index of the first occurrence of the desired target if it is found and -1 if not found: public static int find(int data, int target) {for (int i = 0; i < data.length; i++)if (data[i] == target)return i;return -1;}List a set of test conditions to use to test this method as completely as possible. Write a set of Javadoc comments to document this method....
View Full Document

Page1 / 5

homework2 - 15-121 FALL 2009 (Reid-Miller)HOMEWORK 2* - due...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online