COM1204 Object-Oriented Design

Midterm Exam (Outline) -- Thursday, May 17th

Spring 2001 -- Professor Futrelle
College of Computer Science, Northeastern U., Boston, MA


This outline lists the questions in part, with certain important details from the actual test(s) missing. This should help you focus your studying for the Midterm. In each question, in red, are suggestions as to what you'll need to know in order to answer the questions correctly.

Question 1.

Write a simple class with two methods method1() and method2() that have distinct implementations but are each members of the specificand set for the following specification:

"... specification omitted ..."

For this question you'll need to understand what it means to have distinct implementations of a function. Furthermore, you must write Java code as part of your answer to the question. The code will involve logical expressions that test relationships between numerical values, if statements, returns, etc.

Question 2.

Write two specifications, one more general than the one below and the other more specific.

"... specification omitted ..."

What you're being asked here is to change the specification, not rewrite exactly the same specification in different words. That is, the specification that I give you can be made more general to allow more implementations and a greater variety of results, or it can be made more restrictive so that only very specific inputs, processing and outputs are allowed. See Chapter 9.

Question 3.

3A. Describe how you could do a black-box test of a function with the following specification. No code is required but you should list some typical arrays and values of n you would use and explain your choices.

"... specification omitted ..."

Here, the testing must be based entirely on the specification, not on any knowledge of the implementation. But your tests may be influenced by the fact that you know that you are dealing with an array and indexing into the array.

3B. Given the following implementation of fn1(), describe in some detail how you could do a glass-box test of the function. No code is required but you should list some typical arrays and values of n you would use and explain your choices. In addition, describe how your choices of arrays and n values changed between parts A and B of the question due to the fact that you were now doing glass-box testing.

    ... source code will be supplied here ...
    

In the exam, you'll see source code above and knowledge of it will influence the types of testing you want to do and the particular test cases you choose.

Question 4. Assume that the five examples below all cause compile-time or run-time errors. For the compile-time errors, explain what types of problems they would lead to if they were compiled -- that is, what are the reasons that the statements should not be compiled? For the run-time errors, what types of errors will occur at run time?

  ... five examples here ...

The expressions here will be similar to the ones in Chapter 2 that discussed how expressions should be properly formed and what errors can occur if they are not. Exercise 2.5 from the book was on the Quiz and is very similar.

Question 5.

Explain why the constructor in this class P5 "exposes its rep". Describe an example of how you could interfere with the operation of the class by manipulating the exposed object. You should explain your answer in English.

... tiny class definition with constructor here ....

Here you need to understand the various ways that exposing the rep can occur (pgs. 108, 109 and 110-111). You'll then need to examine the class constructor definition provided and explain how and why it does expose the rep.

Question 5: Extra Credit. Write code demonstrating how you could expose the rep of P5, assuming that SomeClass has a public method setVal(int) to set some value within an instance of SomeClass.

Question 6.

Write the REQUIRES, MODIFIES and EFFECTS specifications for the following method which finds largest value in the array that's less than n. HINT: You'll need to examine the code closely to see what assumptions the code makes in finding the result.

... source code of a method here ...

The HINT above gives you the important information you need to study for this question.