Computer Science 120
Introduction to Programming

Spring 2011, Siena College

Lab 4: Bubble Blower
Due: before the start of spring break

This week's lab will give you your first experience with ActiveObjects and animation by implementing a bubble blowing simulation.

You may work alone or with a partner on this lab. There is no pre-lab design this week.

Problem Description

The program begins with a message displayed centered on the canvas. When you press the mouse on the canvas, the message disappears and a bubble begins to grow, centered at the mouse press point. When you release the mouse, the bubble is free to float about the canvas until it pops.

A working solution for this program will appear below. Click inside the applet to interact with it.



Your program should include two Java classes. BubbleBlower is an extension of WindowController that manages the mouse events to create new bubbles and to tell existing bubbles when it's time to stop growing and start floating around. The Bubble class is an extension of ActiveObject that manages one bubble throughout its lifetime: creation, growth, floating, and popping.

In many ways, this example is similar to ones we have seen in class. One difference here is that you need to create your ActiveObject in response to one mouse event, but then modify its behavior in response to another. This means your WindowController will need to remember the bubble it created when you pressed the mouse (at which point it automatically starts to grow on its own - it is an ActiveObject after all), and send it a message to tell it to stop growing. Sending a message is straightforward enough: that's just a method call. The other task is to organize your loop (or, hint, loops) in your Bubble's run method to grow the bubble from the time it is created until the time it receives the message to stop growing, then to have it float around on the canvas for a while, then finally to pop and disappear.

The specifics of how quickly your bubbles grow and how they float are not that important, but strive to make them look nice and to give it as much of a feel for how real bubbles float around as you can. The solution above has the bubbles change velocity randomly, but with a slight preference for "up" rather then "down." Bubbles should float around for several seconds before they pop.

There are no specific extra credit tasks, but you may feel free to propose your own, for up to a total of 2 points.q

Submitting Your Work

Before before the start of spring break, submit your Java program for grading. There are three things you need to do to complete the submission: (i) place a copy of your Java program into your csis120/hw folder under hw6, (ii) print a copy of your program and hand it to your lab instructor, and (iii) demonstrate the execution of your program for your instructor.

Grading Sheet

This lab is worth 25 points, which are distributed as follows:

> FeatureValueScore
Style, Design, and Efficiency
Appropriate comments 3
Good variable names and declaration types 2
Good use of constants 2
Appropriate formatting 1
Efficiency 1
Good overall design 1
Correctness
Instructions displayed, centered, removed 2
Bubble begins growing on press 3
Growth stops when mouse released 4
Bubbles move around realistically 3
Bubbles disappear after a while 3
Extra Credit
Come up with your ideas! 2
Total 25