Computer Science 252
Problem Solving with Java

Fall 2013, The College of Saint Rose

Lab 4: Bubble Blower
Due: 11:59 PM, Wednesday, October 16, 2013

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 in both the x and y directions, 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.

Submitting Your Work

Before 11:59 PM, Wednesday, October 16, 2013, submit your Java program for grading. There are three things you need to do to complete the submission: (i) upload a copy of your Java program (the .java file only) using Submission Box under assignment "BubbleBlower", (ii) print a copy of your program and hand it to your instructor, and (iii) demonstrate the execution of your program for your instructor (2-day grace period for demos).

Don't forget to check your programs for compliance with the Style Guide for CSC 252 Programs


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

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