___________________________________________________________ // header
{
// "Normalize" the parameter by making all letters lowercase
// (use toLowerCase from the String class)
// Set the appropriate instance variable to the value
// specified by the parameter -- remember how to compare
// String objects (for example, you must test to see if the
// parameter is heads)
}
public class Critter
{
private String name;
private int numLegs;
private int numEyes;
// Constructor #1
public Critter()
{
name = "It";
numLegs = 13;
numEyes = 8;
}
// Constructor #2
public Critter (String critterName, int legs)
{
name = critterName;
numLegs = legs;
numEyes = 2;
}
// Constructor #3
public Critter (String critterName, int legs, int eyes)
{
name = critterName;
numLegs = legs;
numEyes = eyes;
}
...
}
Show the state of each of the following Critter objects (by filling
in the diagram below) after instantiation. Indicate which constructor
is executed in each case. (Put the number in the blank beside the
instantiation.)
Critter cat = new Critter ("Isaac", 4); _________
Critter millipede = new Critter ("Twiggy", 1000, 8); _________
Critter monster = new Critter (); _________
int eyes = 1;
int legs = 2;
Critter cyclops = new Critter ("UGH", eyes, legs); _________
cat millipede
_____________ ________________
| | | |
|_____________| name |________________| name
| | | |
|_____________| numLegs |________________| numLegs
| | | |
|_____________| numEyes |________________| numEyes
monster cyclops
_____________ ________________
| | | |
|_____________| name |________________| name
| | | |
|_____________| numLegs |________________| numLegs
| | | |
|_____________| numEyes |________________| numEyes
_______________________________________________________ //header
{
// return a boolean indicating whether or not the circle
// is completely inside the applet window
}
Circle myCircle;
int count = 0;
do
{
// instantiate a new circle
// if it is in the applet window draw it and count it
} while ( _________________________________________________ );
do
{
// Randomly generate the x, y, and radius (as in postlab --
// you don't need to fill that code in here
.....
} while ( _______________________________________________ );