Animated Smileys

Lab Assignment 2

This assignment gives you additional practice in basic Java programming, including use of if statements and simple loops: You enhance the previous Smiley program to have a smiley group's faces bounce around a graphics window.


Pair Programming

You are required to pair program for this assignment.


Program Behavior and General Requirements

When you run a (correctly) implemented version of this program, a graphics window appears, with from one to three smiley faces (a smiley group) in it; the exact shape and color of the faces are up to you, provided each face must be small enough that it can bounce around the graphics window and is recognizable as a smiley face. Each smiley heads off towards a wall, an edge of the graphics window. When it hits the wall it should

  1. Change the color of its face to the color of the wall, and the wall color should become the color of the smiley face; in other words, the colors swap.

  2. Rebound from the wall, either directly (going back the way it came), or at 45 degrees up or down (if it hit the left or right wall) or 45 degrees left or right (if it hit the top or bottom wall); the direction is randomly chosen and each direction has an equal probability of occurring.

Thie behavior repeats: Every time a smiley hits a wall, it and the wall swap colors and the smiley rebounds, heading to another wall. It continues for a given number of milliseconds, set as a constant in the program.

Closing the window ends the program, (even if the window is closed while the smileys are still moving).


Technical Details

For this assignment, we've again helped you get started by providing some code and lots of comments and documentation. We provide several already-written classes, in compiled form, that provide functions you will likely need to use in your program. SmileyFace, SmileyFacePart, BouncingDisplay and WallName have public methods or constants you may need to employ, so we included text files, SmileyFace.txt, SmileyFacePart.txt, SmileyDisplay.txt, and WallName.txt that describe them. You may be surprised that SmileyFace and SmileyFacePart are not provided in source code form, since you wrote those classes in the last assignment. But that is exactly the point: having written and thoroughly tested them, we can now use their methods to make and manipulate smiley face characterisics without paying attention to the class' details; we don't need the source to use the class' capabilities.

You are to complete the classes AnimatedSmiley, BouncingGroup and SmileyAnimation. Detailed comments in the code describe the public methods each class is to provide. You are free--and encouraged--to add whatever private methods, fields and contants are needed to "help" the public methods so their jobs, and to produce a well-designed, stylish program; comments in code give several suggestions on how you might go about this. (Once you have learned about interfaces, we'll be able to give to you, in a more formal and enforceable form, the information about public methods a class is required to provide.)

All these files have been collected into an Eclipse project and zipped into an archive called Lab2.zip. Using the same procedure that you followed in the last assignment, import this project into your Eclipse workspace.


Testing Tips

It's typically fastest to implement and debug a program when it is done in stages; when something goes wrong, you know it was because of changes made at the current stage, thus reducing the amount of code you have to search to find the mistake. Testing in stages can take many forms. For this assignment, testing in stages boils down to adding and testing a method or two at a time, judiciously choosing them so that, as you add them, you are incrementally heading to a completed program.

For example, here's an outline of one way to incrementally implement and test your program:


Deliverables

Zip up your project folder into the file AnimatedSmileys.zip, and turn it in via Checkmate.


Written by Norman Jacobson for ICS 21 Fall 2006, October 2006.
Minor edits by Norman Jacobson, December 2006 and September 2008.
Minor edits to reflect use of Eclipse, by Norman Jacobson September 2009.
  Includes some text adapted from Alex Thornton's "Lab 2" for ICS 21 Summer 2009.
Minor edits by Norman Jacobson September 2010.
Minor revision to make clear that all directions of return after bouncing off a wall
  have the same probability, by Norman Jacobson November 2010.
Revised for ICS 45J Fall 2012, by Norman Jacobson, August 2012.
Deliverables section added, by Norman Jacobson, October 2012.