homework2_001 - 15-121 FALL 2009 [CORTINA]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 [CORTINA]HOMEWORK 2 - due Wednesday, Sep 9 by 11:59PMElectronic handin for this assignment will be available starting Thurs by 5:00PM.PROBLEMS (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).Try not to compile any code answers since these problems are meant to test your skill solving written problems without the aid of a compiler. (Of course, once you solve the problem, you can use the computer to check your answers, but remember to try to solve the problems yourself on paper before using the computer to check since your written exams will not include the use of a computer to check your answers.) 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. comments to document this method....
View Full Document

This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.

Page1 / 5

homework2_001 - 15-121 FALL 2009 [CORTINA]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