Skip to content
Permalink
Browse files
simuduck
  • Loading branch information
aa6164 committed Feb 6, 2020
1 parent 94bb62a commit 0ffe732da5bd20afa3678cf64f46f94d1a465d28
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 0 deletions.
@@ -0,0 +1,35 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
abstract class Duck {

protected FlyBehaviour flyBehaviour;
protected QuackBehaviour quackBehaviour;

public abstract void display();

public void swim() {
System.out.println("I am swimming!");
}

public void performFly() {
flyBehaviour.fly();
}

public void performQuack() {
quackBehaviour.quack();
}

public void setFlyBehaviour(FlyBehaviour behaviour) {
this.flyBehaviour = behaviour;
}

}
@@ -0,0 +1,14 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public interface FlyBehaviour {
public void fly();
}
@@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class FlyNoWay implements FlyBehaviour {

@Override
public void fly() {
System.out.println("I cannot fly!");
}

}
@@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class FlyWithWings implements FlyBehaviour {

@Override
public void fly() {
System.out.println("I am flying with wings!");
}

}
@@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class MallardDuck extends Duck {

public MallardDuck() {
super.flyBehaviour = new FlyWithWings();
super.quackBehaviour = new Quack();

System.out.println("Created a Mallard Duck");
}

@Override
public void display() {
System.out.println("Displays a Mallard Duck");
}


}
@@ -0,0 +1,21 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class MuteQuack implements QuackBehaviour {

@Override
public void quack() {
System.out.println("Mute quack...");
}



}
@@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class Quack implements QuackBehaviour {

@Override
public void quack() {
System.out.println("I am quacking!");
}

}
@@ -0,0 +1,14 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public interface QuackBehaviour {
public void quack();
}
@@ -0,0 +1,26 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class RedheadDuck extends Duck {

public RedheadDuck() {
super.flyBehaviour = new FlyWithWings();
super.quackBehaviour = new Quack();

System.out.println("Created a Redhead Duck");
}

@Override
public void display() {
System.out.println("Displays a Redhead Duck");
}

}
@@ -0,0 +1,26 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class RubberDuck extends Duck {

public RubberDuck() {
super.flyBehaviour = new FlyNoWay();
super.quackBehaviour = new Squeak();

System.out.println("Created a Rubber Duck");
}

@Override
public void display() {
System.out.println("Displays a Rubber Duck");
}

}
@@ -0,0 +1,19 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class Squeak implements QuackBehaviour {

@Override
public void quack() {
System.out.println("I make a squeak noise!");
}

}
@@ -0,0 +1,26 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package simuduck;

/**
*
* @author aa6164
*/
public class WoodenDuck extends Duck {

public WoodenDuck() {
super.flyBehaviour = new FlyNoWay();
super.quackBehaviour = new MuteQuack();

System.out.println("Creates a wooden duck");
}

@Override
public void display() {
System.out.println("Displays a wooden duck!");
}

}

0 comments on commit 0ffe732

Please sign in to comment.