Created creature hierarchy.

This commit is contained in:
Ilkka Seppala 2015-04-23 21:46:44 +03:00
parent 283388b7b9
commit bb28276937
8 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package com.iluwatar;
public abstract class AbstractCreature implements Creature {
private String name;
private Size size;
private Movement movement;
private Color color;
public AbstractCreature(String name, Size size, Movement movement, Color color) {
this.name = name;
this.size = size;
this.movement = movement;
this.color = color;
}
@Override
public String toString() {
return String.format("%s [size=%s, movement=%s, color=%s]", name, size, movement, color);
}
@Override
public String getName() {
return name;
}
@Override
public Size getSize() {
return size;
}
@Override
public Movement getMovement() {
return movement;
}
@Override
public Color getColor() {
return color;
}
}

View File

@ -0,0 +1,17 @@
package com.iluwatar;
public enum Color {
DARK("dark"), LIGHT("light"), GREEN("green"), RED("red");
private String title;
Color(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}

View File

@ -0,0 +1,12 @@
package com.iluwatar;
public interface Creature {
String getName();
Size getSize();
Movement getMovement();
Color getColor();
}

View File

@ -0,0 +1,8 @@
package com.iluwatar;
public class Dragon extends AbstractCreature {
public Dragon() {
super("Dragon", Size.LARGE, Movement.FLYING, Color.RED);
}
}

View File

@ -0,0 +1,8 @@
package com.iluwatar;
public class Goblin extends AbstractCreature {
public Goblin() {
super("Goblin", Size.SMALL, Movement.WALKING, Color.GREEN);
}
}

View File

@ -0,0 +1,17 @@
package com.iluwatar;
public enum Movement {
WALKING("walking"), SWIMMING("swimming"), FLYING("flying");
private String title;
Movement(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}

View File

@ -0,0 +1,8 @@
package com.iluwatar;
public class Octopus extends AbstractCreature {
public Octopus() {
super("Octopus", Size.NORMAL, Movement.SWIMMING, Color.DARK);
}
}

View File

@ -0,0 +1,22 @@
package com.iluwatar;
/**
*
* Enumeration for creature size.
*
*/
public enum Size {
SMALL("small"), NORMAL("normal"), LARGE("large");
private String title;
Size(String title) {
this.title = title;
}
@Override
public String toString() {
return title;
}
}