-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimal.java
More file actions
49 lines (41 loc) · 907 Bytes
/
Animal.java
File metadata and controls
49 lines (41 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class Animal implements Cloneable {
protected int age;
protected int size;
protected Person owner;
protected Habitat habitat = new Habitat();
public Animal() {
this.age = -1;
this.size = -1;
}
public Animal(int age, int size) {
this.age = age;
this.size = size;
}
public Person getOwner() {
return owner;
}
public void setOwner(Person p) {
owner = p;
}
public String getHabitatName() {
return habitat.getName();
}
public void setHabitatName(String name) {
habitat.setName(name);
}
public String toString() {
String output = "Age = " + age + "; Size = " + size + "; Habitat: " + habitat;
if (owner != null )
return output + "; Owner: " + owner;
else {
return output;
}
}
@Override public Animal clone() {
try {
return (Animal)super.clone();
} catch(CloneNotSupportedException e) {
throw new AssertionError(); // Can't happen
}
}
}