turn(); } When a client class constructs a ChameleonCritter why is it blue, facing north? It inherits the constructor from the Critter class. It inherits the constructor from the Actor class. It inherits the methods getColor() and getDirection() from the Actor class. The compiler adds the following code to the ChameleonCritter class: public ChameleonCritter() { super(); } which calls the default constructor from the Actor class. The compiler adds the following code to the ChameleonCritter class: public ChameleonCritter() { setColor(Color .BLUE); setDirection(Location.NORTH); } COMPUTER SCIENCE SECTION II Time—1 hour and 45 minutes Number of questions—4 Percent of total grade—50 Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN Java. Write your answers in pencil only in the booklet provided. Notes: Assume that the classes in the Quick Reference have been imported where needed. Unless otherwise stated, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods may not receive full credit. Pig Latin is a made-up language sometimes used by children. Here are the rules for converting an English word to Pig Latin. If the word begins with a consonant, move the consonant to the end of the word and add “ay” after it. If the word begins with a vowel, add “yay” to the end of the word. Examples: English Pig Latin dog ogday Apple Appleyay
* that is, hours 12 and minutes 30. */ public void replaceDefective() Consider the hierarchy of classes shown for a small part of a bird sanctuary. Notice that an Owl is-a Bird, a SnowyOwl is-a Owl, and an ElfOwl is-a Owl. The class Bird is specified as an abstract class as shown in the following declaration. Each Bird has a name and a noise that are specified when it is constructed. public abstract class Bird { private String myName; private String myNoise; /** * Constructor for objects of class Bird */ public Bird(String name, String noise) { myName = name; myNoise = noise; } public String getName() { return myName; } public String getNoise() { return myNoise; } public abstract String getFood(); } An Owl is a Bird whose noise is “hoot”. The food it eats depends on the type of Owl, which means that getFood cannot be implemented in the Owl class. Given the hierarchy shown above, write a complete class declaration for the class Owl, including its constructor
Write the modified act method in the Critter class. The act method processes actors as before, “eating” each neighboring adjacent Actor that is neither a Rock nor another Critter. Then it uses a random number to determine whether this Critter will breed or not. If the random number is within the probability range for breeding, the Critter will breed; otherwise it will move as in the original act method. Complete method act below. /** * A critter acts by getting a list of its neighbors, and * processing them. If it passes the probability test for * breeding, then it breeds into each of the empty neighboring * locations. If not, it gets the possible locations to move * to, selects one of them, and moves to the selected location. */ public void act()