Skip to content

Commit bb28276

Browse files
committed
Created creature hierarchy.
1 parent 283388b commit bb28276

File tree

8 files changed

+133
-0
lines changed

8 files changed

+133
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.iluwatar;
2+
3+
public abstract class AbstractCreature implements Creature {
4+
5+
private String name;
6+
private Size size;
7+
private Movement movement;
8+
private Color color;
9+
10+
public AbstractCreature(String name, Size size, Movement movement, Color color) {
11+
this.name = name;
12+
this.size = size;
13+
this.movement = movement;
14+
this.color = color;
15+
}
16+
17+
@Override
18+
public String toString() {
19+
return String.format("%s [size=%s, movement=%s, color=%s]", name, size, movement, color);
20+
}
21+
22+
@Override
23+
public String getName() {
24+
return name;
25+
}
26+
27+
@Override
28+
public Size getSize() {
29+
return size;
30+
}
31+
32+
@Override
33+
public Movement getMovement() {
34+
return movement;
35+
}
36+
37+
@Override
38+
public Color getColor() {
39+
return color;
40+
}
41+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.iluwatar;
2+
3+
public enum Color {
4+
5+
DARK("dark"), LIGHT("light"), GREEN("green"), RED("red");
6+
7+
private String title;
8+
9+
Color(String title) {
10+
this.title = title;
11+
}
12+
13+
@Override
14+
public String toString() {
15+
return title;
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.iluwatar;
2+
3+
public interface Creature {
4+
5+
String getName();
6+
7+
Size getSize();
8+
9+
Movement getMovement();
10+
11+
Color getColor();
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class Dragon extends AbstractCreature {
4+
5+
public Dragon() {
6+
super("Dragon", Size.LARGE, Movement.FLYING, Color.RED);
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class Goblin extends AbstractCreature {
4+
5+
public Goblin() {
6+
super("Goblin", Size.SMALL, Movement.WALKING, Color.GREEN);
7+
}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.iluwatar;
2+
3+
public enum Movement {
4+
5+
WALKING("walking"), SWIMMING("swimming"), FLYING("flying");
6+
7+
private String title;
8+
9+
Movement(String title) {
10+
this.title = title;
11+
}
12+
13+
@Override
14+
public String toString() {
15+
return title;
16+
}
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.iluwatar;
2+
3+
public class Octopus extends AbstractCreature {
4+
5+
public Octopus() {
6+
super("Octopus", Size.NORMAL, Movement.SWIMMING, Color.DARK);
7+
}
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.iluwatar;
2+
3+
/**
4+
*
5+
* Enumeration for creature size.
6+
*
7+
*/
8+
public enum Size {
9+
10+
SMALL("small"), NORMAL("normal"), LARGE("large");
11+
12+
private String title;
13+
14+
Size(String title) {
15+
this.title = title;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return title;
21+
}
22+
}

0 commit comments

Comments
 (0)