Abstract classes, interfaces and polimorfism.
Polimorfismul
Clase abstracte si interfete
Thinking in Java : Chapter 7 - Polimorphism
Diagrama de clase
Implementarea diagramelor UML in Java
Follow the instructions and implement the program according to specification . Create an appropriate test class for testing the program.
In this exercise, Shape shall be defined as an abstract class, which contains:
Create the UML class diagram for the program bellow. Add a new type of bird, and modify BirdController in order to handle the new type of bird.
class Bird { public void move(){ System.out.println("The bird is moving."); } } class Penguin extends Bird{ public void move(){ System.out.println("The PENGUIN is swiming."); } } class Goose extends Bird{ public void move(){ System.out.println("The GOOSE is flying."); } } public class BirdController{ Bird[] birds = new Bird[3]; BirdController(){ birds[0] = createBird(); birds[1] = createBird(); birds[2] = createBird(); } public void relocateBirds(){ for(int i=0;i<birds.length;i++) birds[i].move(); } private Bird createBird(){ int i = (int)(Math.random()*10); if(i<5) return new Penguin(); else return new Goose(); } public static void main(String [] args){ BirdController bc = new BirdController(); bc.relocateBirds(); } }
Implement application based on the UML class diagram bellow. Create a test class for testing the program.