1 Abstract Classes
2 Designing a Game

Lab 4

Goals: The goals of this lab is to learn how to design and use abstract classes, and how to design interactive games using the javalib game libraries.

1 Abstract Classes

The following class diagram represents a library system that records the books that have been borrowed. There are three kinds of books: regular books, reference books, and audio books.

Reference books can be taken out for two days, other kinds of books for two weeks. The overdue fees are 10 cents per day for reference books and regular books, but 20 cents per day for audio books.

For reference book there is no author, only the title.

The day when the book it taken out and the day due are counted as days since the library opened in 2001. So, possibly, an audio book taken out today would have been recorded as taken out on the day 4300 with due date on the day 4314.


               | IBook |


                  / \




       |                  |                  |

+---------------+  +---------------+  +---------------+

| Book          |  | RefBook       |  | AudioBook     |

+---------------+  +---------------+  +---------------+

| String title  |  | String title  |  | String title  |

| String author |  | int dayTaken  |  | String author |

| int dayTaken  |  +---------------+  | int dayTaken  |

+---------------+                     +---------------+

For all methods, think carefully whether they should be designed as concrete methods in the abstract class, abstract methods that are defined in the concrete classes, or concrete methods in the abstract class that are overridden in one of the concrete classes.

2 Designing a Game

Learn how to draw shapes using the javalib.funworld library.


To see how a game is designed, start a new project named AppleOrchardGame.

Download the following three files:

Add the three files source files in the AppleOrchard.zip file to your project.

Unzip the Images.zipfolder and add all files to your project. (Save all image files in the Eclipse project directory that contains the src and bin folders.)

Add the javalib.jar file to the project’s class path (as you have done with the tester.jar library.

You can run the project in two ways. To see the display of the images and to run the game, open the AppleOrchardRunner file and click on the small green Run button on the top. It displays the apple and the basket image in one Canvas, the image of the game scene in a second Canvas, and runs the game in a third window frame.

To run the tests, set up a Run Configuration for the class ExamplesAppleOrchard.

The program illustrates the use of the javalib.funworld library that allows you design an interactive graphics-based game controlled by timer events and key presses.}

Complete documentation of the library with samples is available at http://www.ccs.neu.edu/javalib/World/.

Apple Orchard Game

You are now ready to design your first game. The canvas has a picture of apple tree. An apple falls down (controlled by the tick events). The player moves the basket on the ground, trying to catch the falling apple. The game ends when the player has caught ten apples. (Optionally, you may show the amount of time the player took to catch the apples.)

Well, this is the plan. For now, only one apple is falling, there is no check whether the basket has caught an apple, no count of falling apples, no new apples fall down once the lone apple had hit the ground.

So, you have your work cut out for you.