COMP 110-001 - Introduction to Programming (Spring 2009)
Program 2: BlobManager
50 points
Assigned: Monday, February 9th
Due: Wednesday, February 18th by midnight
Part 1: Download the files, Compile, and Run
On the course webpage, you will find Blob.java and BlobManager.java. Download both files into the COMP110 directory
you use with jGRASP. Modify the Program Header in "BlobManager.java" to reflect your name and due date.
You can now compile and run "BlobManager.java". A window will then pop up with your very own pet blob named Roberto. At this point you can feed
Roberto some pizza, shrink him back to his original size, or change his color. However, you will notice that a couple of the functions don't work entirely the way
that they should. For example, feeding him only one slice gives him five pieces of pizza. If you change his color to purple, it becomes red instead!
Also, even when he grows to be a decent sized fellow, his size is still listed as "Tiny".
Part 2: Modify the Code
Inside of "BlobManager.java", there are four methods that need code modifications to fix the problems above.
Add your code for each item between where you see the comments:
/* ************ MAKE CHANGES HERE ************ */
(your code goes here)
/* *************** END CHANGES *************** */
NOTE: You do not need to modify any code in "Blob.java", nor should you modify any code in "BlobManager.java" outside of the above comments. One exception
is that you are welcome to rename your blob from "Roberto" in the main method of "BlobManager.java" (only if you would like).
- getBlobColor(int colorNumber)
This method will take in a number as a parameter that corresponds to a color
that we want to change the blob to (see table below). If a number other than 0-3 is
specified, the color should default to green. Currently this method has a series
of if-then statements that only work for two cases.
You must modify this code to use a switch statement instead and be correct for all cases.
You should use the constants declared at the top, as shown in the if statements already
in place. Use the following table for reference:
int colorNumber | Color |
0 | GREEN |
1 | RED |
2 | BLUE |
3 | PURPLE |
Any other number | GREEN |
- feedPizzaToBlob(int numSlices)
This method will repeatedly call the feed() method for the blob
so that we can feed it some pizza. The feed() method must be called
the number of times indicated in "numSlices". Currently it is called five times
regardless of the value of "numSlices". You need to modify this to do it the
correct number of times for any value of "numSlices".
- getBlobSizeAsString(int blobDiameter)
This method will provide a textual representation for a specific blob
diameter. If the blob diameter is 75, for example, your blob is classified
as "Medium". You need to modify this method to include a series of if/else statements
that will print the correct String corresponding to each diameter,
as defined in the table below:
int blobDiameter | String blobSize |
smaller than 20 | "Microscopic" |
20 to 29 | "Tiny" |
30 to 49 | "Small" |
50 to 79 | "Medium" |
80 to 119 | "Large" |
120 to 169 | "Extra Large" |
170 to 229 | "Massive" |
230 or larger | "Whoa Momma!" |
- calculateBlobDiameter(int area)
This method will calculate the diameter of the blob given its area. The current
formula is incorrect. You will need to use the
Math.sqrt()
function, which is similar in nature to that of Math.ceil() used in the last assignment.
Keep in mind that sqrt() and ceil() return doubles, and that the storage location
for diameter is an int.
I've included a constant value called PI that you may use as well.
Here is what a modified version would look like after feeding him 1000 pizza slices and
changing his color to purple.
Submission
For this assignment you will need to create a Jar file that contains the source code for your program.
Follow these instructions for creating a Jar file.
The Jar file you submit must be named yourlastname_pro2.jar, where yourlastname is your last name.
Submit yourlastname_pro2.jar via the UNC Blackboard System
before the deadline.
Requirements & Grading
If your java file does not compile or is submitted/named improperly, your maximum score is 0.
- [3] Program Header edited correctly
- [3] JAR file submitted and named correctly (as specified above)
- [11] getBlobColor() edited correctly
- [11] feedPizzaToBlob() edited correctly
- [11] getBlobSizeAsString() edited correctly
- [11] calculateBlobDiameter() edited correctly