Computer Science 252
Problem Solving with Java

Spring 2016, The College of Saint Rose

Lab 7: Bubble Blower
Due: 11:59 PM, Wednesday, March 2, 2016

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 to this program can be downloaded here.

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. Note that this breakdown is the same as what we've been doing with custom classes: the WindowController extension class is responsible for the behavior of the program when it starts and in response to mouse events, but the custom class (in this case, an extension of ActiveObject) is responsible for the life of one bubble. It will know about any graphics components that make up the bubble, will create them in its constructor, and will provide additional methods through which the rest of the world can interact with it. The big difference here is that it also needs a run method to manage its animation, which occurs even when no mouse events are being triggered.

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. Avoid having your bubbles fly too quickly off the canvas so we can observe them a bit. 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. Hopefully you can make something that looks a little nicer than the demo.

Here are a few additional tips that hopefully will help you avoid common mistakes:

Grading Note: There will be an extra emphasis on the use of named constants where appropriate, good variable names, declaring variables vs. local variables, and good commenting.

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

Before 11:59 PM, Wednesday, March 2, 2016, submit your lab for grading. There are two things you need to do to complete the submission: (i) Upload a copy of your lab (a .7z or .zip file containing your project directory) to terescoj AT strose.edu. (ii) Demonstrate the execution of your programs for your instructor. (iii) Hand a printout of the Java files that make up the programming assignment to your instructor. (2 business day grace period for demos and printouts).

Grading

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

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