Skip to content

Commit 080546e

Browse files
committed
Added ability to waddle
* Added location to the Foot class, initial value 0 * Added Foot::moveForward() to advance the location * Moved the left and right foot forward in the waddle() function
1 parent 5d0515e commit 080546e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/animals/Penguin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Penguin( int age,
2525
float rightFootLength,
2626
float beakLength )
2727
{
28-
System.out.println("Creating a penguin");
28+
System.out.println( "Creating a penguin" );
2929

3030
// Store values
3131
this.age = age;
@@ -38,4 +38,11 @@ public Penguin( int age,
3838
leftFoot = new Foot( rightFootLength );
3939
beak = new Beak( beakLength );
4040
}
41+
42+
public void waddle()
43+
{
44+
System.out.println( "Creating a penguin" );
45+
leftFoot.moveForward();
46+
rightFoot.moveForward();
47+
}
4148
}

src/animals/parts/Foot.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88
public class Foot
99
{
1010
float length;
11+
int location;
1112

1213
public Foot( float length )
1314
{
14-
System.out.println("Creating a foot");
15+
System.out.println( "Creating a foot" );
1516
this.length = length;
17+
location = 0;
18+
}
19+
20+
public void moveForward()
21+
{
22+
location++;
1623
}
1724
}

0 commit comments

Comments
 (0)