Session 6

Factoring a New Class out of a Program

Computer Science II
Object-Oriented Programming

Implementing a Frame Class

... start with open frames.

... a Frame takes two balls (two int instance variables).
... answers score.

... describe (at least) two ways that a Frame can know where to put the next ball.

... give a Frame three balls.
... answers score.
... ask game score -- fails.
... store two balls, pass one on.

... describe (at least) two ways to create the full set of Frames.

... discuss lazy evaluation, in programming languages and in programs.

... add a Frame instance variable to the Frame class.
... pass third ball on.
... ask frame and game score.

Where Were We?

We want to implement a new feature in our bowling game, the ability to print out the results of the game, in a form similar to what real bowlers use.

a blank scoresheet for bowling

In Session 4, we decided to use this requirement as an opportunity to make our program more in tune with the Principle of Continuity. Our program will now speak in terms of frames, as do bowlers and the rules for scoring the game.

So, we have to do two things:

We could do these at the same time, but that would actually be pretty complicated. Let's stick with our "do simple things" philosophy instead, and do them one at a time.

To write a Frame class, we will use the same process we've been using to write new code: write a test, write the code to make our program pass the test, clean up, and repeat.

To integrate the Frame class into BowlingGame, we will use the same process we've been using to clean up our code: make a small change to the code, run the tests to see what we've broken, fix it, and repeat.

Implementing More of the Frame Class

... work on spare case: one spare, two spares, ten spares.

More on JUnit

... return Homework 1 ...

See JUnit Javadoc in our resources folder...

... the assertXXX methods

... how does JUnit work? ... access to the assertion methods. ... access to the test methods.

On Homework 2

Any questions about Homework 2?

Wrap Up

Eugene Wallingford ..... ..... January 27, 2005