Created
April 17, 2015 20:50
-
-
Save kchodorow/b966c4483f619977fbe5 to your computer and use it in GitHub Desktop.
Homework skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class Zoo { | |
public static void main(String[] args) { | |
ArrayList<Animal> animals = new ArrayList<Animal>(); | |
// Generate 100 random animals. | |
for (int i = 0; i < 100; i++) { | |
double randomNum = Math.random(); | |
if (randomNum < .25) { | |
// TODO: fill in with an animal you define. | |
animals.add(new Kangaroo()); | |
} else if (randomNum < .5) { | |
// TODO: as above. | |
... | |
} else if (randomNum < .75) { | |
// TODO: as above. | |
... | |
} else { | |
// TODO: as above. | |
... | |
} | |
} | |
// Print info for each animal. | |
for (int i = 0; i < animals.size(); i++) { | |
Animal animal = animals.get(i); | |
System.out.println(animal); | |
animal.move(); | |
animal.diet(); | |
} | |
} | |
} | |
class Animal { | |
public void move() { | |
System.out.println("This should never be printed."); | |
} | |
public void diet() { | |
System.out.println("This should never be printed."); | |
} | |
public String toString() { | |
return "Animal"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment