Created
May 10, 2014 03:09
-
-
Save wbashir/4ac27fc562f0d3ca8002 to your computer and use it in GitHub Desktop.
HW5
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
/*Main.java*/ | |
public class Main { | |
public static void main(String[] args) { | |
Animal dog = new Dog(); | |
dog = new Name(dog, "Fido"); | |
dog = new Color(dog, "brown"); | |
Animal cat = new Cat(); | |
cat = new Name(cat, "Felix"); | |
cat = new Color(cat, "white"); | |
Animal fish = new Fish(); | |
fish = new Name(fish, "Nemo"); | |
fish = new Color(fish, "orange"); | |
Animal worm = new Worm(); | |
worm = new Color(worm, "grey"); | |
Animal cricket = new Cricket(); | |
cricket = new Color(cricket, "black"); | |
Animal[] animals = { dog, cat, fish, worm, cricket }; | |
for (Animal animal : animals) | |
System.out.println(animal.getDescription()); | |
} | |
} | |
/*Color*/ | |
public class Color extends AnimalDecorator { | |
private Animal animal; | |
private String color; | |
public Color(Animal animal, String color) { | |
this.animal = animal; | |
this.color = color; | |
} | |
public String getColor(){return color;} | |
public String getDescription() { | |
return animal.getDescription() + " color=" + color; | |
} | |
} | |
/*Cricket*/ | |
public class Cricket extends Animal { | |
public Cricket() { | |
description = "Cricket:: sound=chirp"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment