Question
In this lab, we'll be writing a class hierarchy of Emoji. Here is a UML diagram of the classes we'll be writing: Emoji and Face
In this lab, we'll be writing a class hierarchy of Emoji. Here is a UML diagram of the classes we'll be writing:
Emoji and Face Emoji are abstract classes because they don't have enough information to be useful on their own.
Here's a description of what each class should contain:
Emoji (abstract class):
member variables for position and size of the emoji
constructor taking x, y, size
abstract void draw(). We can't implement this method yet, so it's abstract, but all emoji that inherit from it must have a draw method
FaceEmoji (abstract class):
constructor
void draw() //this will draw the yellow circle and black eyes of the face, but it doesn't have enough information to draw the mouth
SmileyFaceEmoji:
constructor
void draw() //use StdDraw.arc to draw the smiling face
FrowningFaceEmoji:
constructor
void draw() //like smiley face, but sadder
ClockEmoji:
constructor (taking an extra int param for the hour the clock is set to)
void draw() //draw a circle around the border and an "hour hand" line out from the center that shows the correct time
Driver (with main)
In main, read from the emojiInputs.txt file. The file contains information about a grid of emoji. The file starts with the number of rows, then the number of columns.
Then, it lists the emoji that should fill in the grid. "smile" means the emoji should be a SmileyFaceEmoji, "frown" means a FrowningFaceEmoji, and "clock" means ClockEmoji and will always be followed by an integer representing the hour hand of the clock.
Each emoji should be 100 pixels x 100 pixels.
Test your code with a text file containing "4 4 smile frown smile clock 4 clock 8 frown smile clock 3 clock 12 clock 10 smile smile smile frown frown frown"
Your program should produce output similar to this:
Once you have that working, we're going to add a couple of additional methods and test them.
Add a tick() method to the ClockEmoji class that adds one to the hour (it should wrap around at 12).'
Add an additional boolean to the FaceEmoji class named winking. Set it to false in the constructor.
Modify the draw method of your FaceEmoji class so that if it is winking, one of the eyes is drawn as a line instead of a circle.
Add a wink() method to the FaceEmoji class to toggle (flip the value) of your winking member variable.
In main, animate your emoji by calling wink() on the faces and tick() on the clocks and then drawing them. You'll need to use instanceof and typecasts to accomplish this. You should call StdDraw.show(500) inside your animation loop so that they don't update too quickly.
Hopefully you can tell that this isn't the best way to implement animated emoji. We're going to "refactor" our code in order to improve it.
Add a new abstract method named animate() to the Emoji class, then override it in the FaceEmoji and ClockEmoji classes to call the appropriate methods (wink and tick). Comment out the code in main that calls tick() and wink(), and then add code to use the new animate() method. By modifying our program design to add a new abstract method, we've significantly simplified the code.
UML:
Output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started