Session 9

Programs that Process Text

Computer Science II
Object-Oriented Programming

Adding the Print Scoresheet Behavior to BowlingGame

Last time, we refactored the BowlingGame class to use our Frame class. We then started to add the ability to print a scoresheet to the BowlingGame class. The first step is to extend Frame, which will do the work, and the second is to add an onterface method to BowlingGame.

Quick Exercise: How do we test a printing behavior?

Give the object a method that produces a String that we can verify as correct. Use that method to implement the printing behavior.

Issues we encounter:

Exercise: Extend Frame to return correct ballString()s for closing spares and strikes.

... do it together in class ...

Finally, we add methods to BowlingGame to offer this behavior to the client...

Voilá! The BowlingGame satisfies both requirements. And we know this as well as we can, because our tests tell us so.

Remaining smells:

Our code can be made better. A great way to study the code and the course material is to refactor it. Don't be too afraid: the tests will help you be sure not to break the code.

News from the client: It seems that out code has a bug in it. If a bowler rolls a strike in the 10th frame followed by a spare with the two bonus balls, then the printed string should show the spare, say, "X 6 /" instead of "X 6 4". A great way to study the code and the course material is to fix this behavior, by writing a new test and modifying the Frame class.

On Homework 3

Any questions?

An AssociationList has a Vector instance variable. An AssociationList is not a Vector.

Test any special cases you can imagine...

Wrap Up

Eugene Wallingford ..... ..... February 8, 2005