Computer Science 120
Introduction to Programming
Fall 2011, Siena College
Lecture 3: Conditionals and Numbers
Agenda
- Announcements
- Lab 1 this week
- you will know most of what you need to know by the end
of class today
- you will need to do a written design before lab or when
you first arrive in lab - and before you start coding
- we will cover remaining items you need for this lab in
class on Thursday
- Lecture assignment recap
- Remembering information between events
- Counting events
- Named constants
- Conditional execution
Project 1: Interactive Smiley Face
Due Wednesday, September 21
Create the SmileyFace program shown below:
Program requirements:
- When the mouse enters the canvas the mouth should change from a frown to a smile.
- Moving the mouse inside the smiley face should make the head grow.
- Draging the moust inside the smiley face should make the head shrink.
- The smiley face should be composed of seven private field variables (headOutline, headBackground, leftEye, rightEye, mouthSmile, and mouthFrown).
- The controls buttons (the four rectangles in the top right corner) should be named (upButton, downButton, rightButton, and leftButton). These should also be private field variables.
- You should define three constant fields called MOVE_INCREMENT, RESIZE_INCREMENT, and CENTER_ADJUST.
- MOVE_INCREMENT should be an integer and should be set to 5. When the user clicks a control button (up, down, right, or left) all 7 object that makeup the smiley face should be moved in the specified direction by the number of units specified by MOVE_INCREMENT. For example, if the user clicks the down button, the entire smiley face should move down 5 units.
- RESIZE_INCREMENT should be an integer and should be set to 2. When the mouse is inside the smiley face, i.e., headBackground contains the mouse pointer, the height and width of the headOutline and headBackground should be increase according to the RESIZE_INCREMENT. In other words, the head should grow when the mouse is moved inside of the head itself.
- CENTER_ADJUST should be a double and should be set to RESIZE_INCREMENT/2. CENTER_ADJUST should be used to properly re-center the headBackground and headOutline when they are resized.
Examples