___________________________________________________________ // 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 = 1; } // 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 ("Sam", 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
amount += fee; if (validAmount(amount)) { if (amount > balance) { Same as now -- print insufficient funds messages } else balance = balance - amount; } return balance;
_________________________________________________________ // header { //print an error message if the amount is negative // return false if the amount is negative; true otherwise // DO NOT use an if -- just return the value of a boolean // expression }