homework2_001 - 15-121 FALL 2009[CORTINA HOMEWORK 2 due...

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

View Full Document Right Arrow Icon
15-121 FALL 2009 [CORTINA] HOMEWORK 2 - due Wednesday, Sep 9 by 11:59PM Electronic 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 lookupEntry method 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 interface to specify the behavior of a class rather than just implementing the behavior as a class directly? 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; }
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern