-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoo.java
84 lines (58 loc) · 1.93 KB
/
Zoo.java
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
*/
public class Zoo
{
private Cage[] Cages = new Cage[8];
private String name;
//constructor - has same name as class
public Zoo(String zooName)
{
name = zooName;
System.out.println("Welcome to " + name);
for (int i=0; i<8; i++){
Cages[i] = new Cage(i);
}
fillAnimal();
}
public void fillAnimal () {
Animal a;
for (int i=0; i<4; i++) {
a = new Keeshond("Kes"+i, Colour.YELLOW);
recieveAnimal(a);
a = new TibetanMastiff("Tb"+i, Colour.YELLOW);
recieveAnimal(a);
a = new PotBellied("Pb"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Berkshire("Bk"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Labrador("Lab"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Poodle("Po"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Mud("Mud"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Snapping("Sna"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Malayan("Mal"+i, Colour.YELLOW);
recieveAnimal(a);
a = new Bengal("Ben"+i, Colour.YELLOW);
recieveAnimal(a);
}
}
/*
* Constructor for objects of class Zoo
*/
public boolean recieveAnimal(Animal oneAnimal) {
boolean result = true;
//loop through cages to check
for (int i=0;i<8; i++) {
if (Cages[i].addAnimal(oneAnimal)==true)
{
System.out.println("filled" + i + "successfully");
return true;
}
}
System.out.println("filled unsuccessfully");
return false;
}
}