Computer Science 120
Introduction to Programming

Spring 2012, Siena College

Lab 7: Bubble Blower
Due: the start of your next lab session

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 formal design document to be graded this week, but you are strongly encouraged to begin, as usual, with pencil and paper sketching out a plan before you start coding.

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 4 points.

Submitting Your Work

Before the start of your next lab session, 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 hw10, (ii) print a copy of your program and hand it to your instructor, and (iii) demonstrate the execution of your program for your instructor.

Don't forget to check your programs for compliance with the Style Guide for CSIS 120 Programs

Grading

This assignment is worth 100 points, which are distributed as follows:

> FeatureValueScore
Style, Design, and Efficiency
Appropriate comments 6
Good variable names 4
Appropriate variable declarations 8
Good use of constants 8
Appropriate formatting 2
Efficiency/Does not generate new objects unnecessarily 4
Good overall design and methods 8
Program Requirements
Instructions displayed, centered, removed 6
Bubble begins growing on press 10
Bubble drawn centered on press point 10
Bubble grows symmetrically around the point 8
Growth stops when mouse released 10
Bubbles move around realistically 8
Bubbles disappear after a while 8
Extra Credit
Come up with your ideas! 4
Total 100