Lab 3: Bouncing Faces
Pre-Lab Exercises
You should submit these pre-lab exercises by the end of the day Sunday, February 6.
- Read Chapter 5 of textbook Java Concepts.
- Read the description of the Java classes: Dimension and Point.
- Create a README file and enter your answers to the following questions there
- A Color object is immutable; however, Dimension and Point objects are not.
- List three methods that change the state of a Dimension or Point object --- there are no such methods for a Color object.
- In addition to methods, Dimension and Point objects let you change their state directly, i.e., the instance variables are public. For each object, list which instance variables are public. Finally, show an example of how to change these instance variables directly (i.e., without calling a method).
- How does this difference in mutability affect your program. Provide a specific example of the difference you describe.
- Using Eclipse, checkout the project labs/03_prelab
- Change the
update method of the BouncingBall class so that the ball's color gets brighter when it hits the top or right wall and darker when it hits the bottom or left wall. Enter your answers to the following questions in your README file
- Given the initial positions and velocities when you checked out the program, do the colors of each ball tend to become brighter, darker, or stay the same over time?
- What initial velocity, if any, could you give the ball to ensure that its color generally stayed the same over time?
- What initial velocity, if any, could you give a ball so that it becomes so bright or so dark that it cannot get any darker or brighter?
- Change the
draw method of the BouncingBall class so that it draws a collage of at least two different shapes moving together rather than just a simple circle. In other words, all your shapes should appear to move as a single object and when they bounce off a wall, they should all appear to bounce.
- Change the
update method of the BouncingBall class so that it appears that gravity affects each ball as it bounces around. In other words, each ball should slow down as it moves away from the floor and speed up as it moves towards the floor.
- Using Eclipse, submit your README and Java file for assignment prelab03
In-Lab Exercises
You should submit these lab exercises by the end of the day Wednesday, February 9.
- Using Eclipse, checkout the project labs/03_smiley
- Complete the problem Proportion and test your solution using the SAPP testing page within your browser
- Using the Dimension object, add an instance variable to the
BouncingBall class so that it remembers the size of the ball. Thus, instead of using a constant value like RADIUS, each ball could have a different size. Change the constructors of BouncingBall so that the size can be set when the object is created.
- Verify your code by changing the code in
AnimationCanvas that creates the BouncingBall objects so that it creates two ball objects of different sizes.
- Create a class that represents a smiley face that can bounce off the walls like a
BouncingBall. Your smiley face should be able to be constructed with at least a center position, size, and velocity. Your smiley face should have at least a head, two eyes, and mouth that are correctly positioned and sized proportionally to the canter and size given when the class is created. Feel free to be creative about adding extra features to your smiley face (e.g., a hat, nose, teeth, headband, etc.).
- Verify your code by adding to the code in
AnimationCanvas that creates the BouncingBall objects so that it creates two BouncingSmiley objects of different positions and sizes in addition to the original ball objects.
- Create a README file and enter your answers to the following questions there
- How did you determine the correct proportions for the eyes of your smiley face?
- Would constants, rather than fixed numbers in your calculations, have helped make the process any easier?
- Would constants, rather than fixed numbers in your calculations, have helped make the process of adding gravity?
- Given that there are no units in the Java graphics system other than pixels per millisecond, how did you choose a value for gravity so that it produces reasonable results (i.e., the simulation looks good on the screen)?
- Using Eclipse, submit your README and Java files for assignment lab03_smiley
Comments?