Midterm Solutions

Links

Midterm Questions

Evaluation rubric

Problem 1 [10 points]

#ppp = 10

instability(X) = #providers/10 = 4/10 = 2/5 = .4

responsibility(X) = #clients/10 = 4/10 = 2/5 = .4

stability(X) = 1 – instability(X) = 3/5 = .6

deviance(X) = |3/5 – 2/5| = 1/5 = .2

Problem 2

All of the added code is marked in Company.java (contains all of the class declarations.)

Problem 2a [10 points]

class EmployeeVisitor {
   public void visit(Employee e) { }
   public void visit(Programmer e) { }
   public void visit(Manager e) { }
   public void visit(Secretary e) { }
}

Problem 2b [10 points]

class CountProgrammerVisitor extends EmployeeVisitor {
   private int numProgrammers = 0;
   public void visit(Programmer e) {
      numProgrammers++;
   }
   public int getNumProgrammers() {
      return numProgrammers;
   }
}

Problem 2c [5 points]

Added to bottom of Company.main:

CountProgrammerVisitor v = new CountProgrammerVisitor();
acme.visit(v);
System.out.println("# programmers = " + v.getNumProgrammers()); // prints 33

Problem 3 [15 points]

The auctioneer publishes (announces) a new price to the subscribing (registered) bidders. Bidders use a strategy to determine if they will accept the new price. The UML model can be found in auction.uml. Here's a snapshot: