This assignment gives you some more practice in basic Java programming, including practice with if statments and simple loops, by enhancing the previous Smiley program to handle animation of a smiley face as it interacts with the walls (boundaries) of the graphics window.
In general, you are to complete the Java class SmileyAnimation, which weve added to the Smiley program so that smiley faces can be animated.
When Smiley is run, a graphics window appears, with a smiley face in it; the exact shape and color of the face are up to you, within the bounds that the face must be small enough that it can move around within the graphics window, and be recognizable as a smiley face (you will use the previously written SmileyFace class to make it). That smiley heads off towards a wall, an edge of the graphics window. When it hits the wall it should
This behavior continues for a number of milliseconds, set as a constant in the program; every time the smiley hits a wall, it and the wall swap colors and the smiley rebounds, heading to another wall.
The user clicks on the close box to close the window and end the program; if the close box is clicked while the smiley is still moving, the program still shuts down.
For this assignment, weve again helped you get started by providing some code and lots of comments and documentation. All your work is done in the SmileyAmination class. We provide several already-written class files that provide functions you will likely need to use in your program. Two of these, SmileyFace and SmileyDisplay, have public methods or constants you may need to employ, so we included text files, SmileyFace.txt and SmileyDisplay.txt, describing those public items. You may be surprised that SmileyFace is not provided in source code form, since you wrote that class in the last execise. But that is just the point: having written and thoroughly tested it, we can now use its methods to make and manipulate smiley face characterisics without paying attention to the class details; we dont need the source to use the class capabilities.
These files are stored together in the archive file Lab2.zip. Download Lab2.zip to your computer and unzip it into its own folder. Replace all spaces marked // Your code goes here with your own Java code to obtain a complete, correctly working program.
As before, when compiling the program, use the command javac *.java to ensure all parts of the program are recompiled. (For more on this, see the Orientation to the Lab section of the manual.) Run the program with the command java Smiley.
Do remember that a significant failure to follow class style standards on a lab exam can result in a not pass for that exam.
Its 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, since all the methods you are writing are in one class, 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, heres an outline of one way to incrementally implement and test your program:
Lab exam #2 will be very similar, but perhaps not identical, to the program you are to code for this exercise.
The lab exam will have you code one or more of the following methods from the SmileyAnimation class:
Remember to read over the lab exams program comments before beginning; they will tell you what you are to complete and give any particulars (such as, for example, the characteristics of a smiley face you are to draw or the kind of movement it should exhibit when animated).