1 Abstract Classes
2 Designing a Game
5.3.5

Lab 4

Goals: The goals of this lab is to learn how to design and use abstract classes, and how to design intteractive 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

All files you need for this project are in the Lab4.zip file. Download it to find the files you need below.

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

Introduction

To see how a game is designed, start a new project named MyFirstGame. Add the file BlobWorldFun.java to the project’s src folder. Add the image file small-shark.png to your project folder. Add the javalib.jar file to the project’s class path. Run the project (the tests are defined in the ExamplesBlobWorld class).

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

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.)

Do as much as you can in the lab. Finish this game as a part of your protfolio problems.