___________________________________________________________ // 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 the string "heads" or the string "tails") }
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
public static final int WIDTH = 600; // width of the graphics object // a circle will be drawn on public static final int HEIGHT = 400; // height of the graphics object private static Random generator = new Random();
System.out.println ("Assumed applet width: " + __________________________________);
public Circle () { final int MAX_COLOR = (int)Math.pow(2,24) - 1; x = generator.nextInt(WIDTH); y = generator.nextInt(HEIGHT); diameter = generator.nextInt(75) + 75; color = new Color (generator.nextInt(MAX_COLOR)); }Clearly the circle generated may not fit completely within the applet window which may be ok in some applications but not others. It would be nice for the class to provide a method to determine whether the circle fits or not. Write a method inBounds that has no parameters and returns a boolean value - true if the circle generated is totally in the bounds of the applet and false otherwise. This should be done with a single statement - a return of a boolean expression.
_______________________________________________________ //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 random circle // if it is in the applet window draw it and count it } while ( _________________________________________________ );
do { // Randomly generate the x, y, and diameter (as in the constructor // above -- you don't need to fill that code in here) ..... } while ( _______________________________________________ );