Skip to content

Commit ba27526

Browse files
committed
Added ability to interact with Penguins at the Zoo
* Added a constant for Zoo to track number of penguins in the zoo * Added filed for array of penguins (instead of hard coded penguins) * Added accessor to get the penguins at the zoo * Added field for Penguin name * Added name to constructor of Penguin
1 parent 10433a7 commit ba27526

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/Zoo.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,40 @@
77
*/
88
public class Zoo
99
{
10-
Penguin waddles;
11-
Penguin fluffy;
10+
static final int NUMBER_OF_PENGUINS = 2;
11+
12+
Penguin[] penguins;
1213

1314
public Zoo()
1415
{
15-
waddles = new Penguin( 10, 150, "green", "blue", 12.0f, 11.0f, 6.0f );
16-
fluffy = new Penguin( 2, 2000, "black", "black", 24.0f, 24.0f, 10.0f );
16+
penguins = new Penguin[NUMBER_OF_PENGUINS];
17+
penguins[0] = new Penguin( "Waddles",
18+
10,
19+
150,
20+
"green",
21+
"blue",
22+
12.0f,
23+
11.0f,
24+
6.0f );
25+
26+
penguins[1] = new Penguin( "Fluffy",
27+
2,
28+
2000,
29+
"black",
30+
"black",
31+
24.0f,
32+
24.0f,
33+
10.0f );
1734
}
1835

19-
public static void main(String[] argv)
36+
public static void main( String[] argv )
2037
{
2138
Zoo zoo = new Zoo();
2239
System.out.println("Hello, I have a zoo!");
2340
}
41+
42+
public Penguin[] getPenguins()
43+
{
44+
return penguins;
45+
}
2446
}

src/animals/Penguin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
public class Penguin extends Animal
1313
{
14+
String name;
15+
1416
Eye leftEye;
1517
Eye rightEye;
1618
Foot rightFoot;
@@ -19,7 +21,8 @@ public class Penguin extends Animal
1921

2022
boolean isHungry;
2123

22-
public Penguin( int age,
24+
public Penguin( String name,
25+
int age,
2326
int weight,
2427
String leftEyeColor,
2528
String rightEyeColor,
@@ -30,6 +33,7 @@ public Penguin( int age,
3033
System.out.println( "Creating a penguin" );
3134

3235
// Store values
36+
this.name = name;
3337
this.age = age;
3438
this.weight = weight;
3539

0 commit comments

Comments
 (0)