CS160 Take Home Midterm (10/28/99)







Consider the following implementation of a stack data structure in Java:

class Stack {
private Object[] elements;
  private int count = 0;
  Stack (int max) { elements = new Object[max]; count = 0; }
  public boolean push(Object elem) { 
    if (count >= elements.length) return false;
    elements[count++] = elem; return true;
  public Object pop() { 
    if (count <= 0) return null;
    return elements[--count];

a. Discuss what type of elements can be stored in an object of type Stack? (10 points)

b. Is the following piece of code legal in Java? (5 points)

    Stack s = new Stack(10);
    Integer i = new Integer(1);
    Stack s1 = new Stack(5);

c. What would happen if the following two statements are added to the code in part (b)? (5 points)

    i = (Integer)s.pop();
    s1 = (Stack)s.pop();

d. Suppose that a stack data structure, say EmpStack, is required that should store only objects of type Employee class and its sub-classes. How would you use the stack implementation given above, to define EmpStack? (10 points)

e. Even though Java has no pointers, we can use the reference feature to implement dynamic data structures such as stacks and queues in Java. Thus the reference feature can handle everything pointers can handle. Is this true? (10 points)




Do you agree with the following guideline for software acquisition for Airforce? Why? Justify your answer. (10 Points)
"The waterfall method is not recommended for major software-intensive Air Force acquisition programs."




Analyze the expert system development lifecycle using the waterfall model. And what is your suggestion(s) on improving the expert system development lifecycle ? (10 points)




Scenarios are used in both the CRC card and Rational Rose. Describe at least three ways scenarios can be useful in software development. This is a thinking question, think hard before you answer. (15 points)




For this question, all I need is hardcopy printout for grading, please print all the solutions regardless if you are using Rose or not.

A cross traffic intersection needs two traffic controllers. To simplify the problem, this particular intersection does not allow pedestrains to cross the streets, thus traffic signals are needed for cars only. The traffic controller issue GREEN, YELLOW and RED signals. You may assume that the cross streets are either NS or EW. Each GREEN signal last for 20 seconds, YELLOW 2 seconds.

a. Suggest an object model for the controllers. Please specify classes and their subclasses, and their methods and attributes. Define and describe your methods including the signatures, i.e. parameter definitions. (10 points)

b. Draw a state transition diagram involving two controllers. (5 points)

c. Draw two scenario diagram for your solution (10 points)




Whole-Part Pattern Question

Name one example of using the Whole-Part pattern and states that why Whole-Part is usable in the case you specified. (5 points)




Describe 2 advantages and 2 disadvantages for the Command Processor Pattern (5 points)



QUESTION 8 - Java Programming for Extra Credit (40 points)

Develop a binary tree program using Java. Note that Java does not have pointers but your tree still must be able to contain arbitrary number of records.

The answer should have at least two parts.

One for the B-tree implementation

The other as a testing program which do exercise such as create tree, show tree, insert element, delete element and find element. The interface to this program could be text based or SWING based for extra credit (see below).

(Please print out detail instruction on how to compile and run the program. Please document the source code as well.)



QUESTION 8.5 - Java Programming Extra Credit (20 points)

Improve your answer in question 8 by providing a SWING interface for creation of b-tree, inserting, deleting and finding elements in your binary tree.