Skip to content

Commit

Permalink
added ability to give your turtle a name
Browse files Browse the repository at this point in the history
  • Loading branch information
lynnlangit committed Feb 24, 2017
1 parent b8f9e9f commit bb03ad1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/org/teachingextensions/logo/Tortoise.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ public static void show()
{
turtle().show();
}
/**
* Gets the name for the tortoise
* <div><b>Example:</b> {@code String name = Tortoise.getName("Anita Borg");}</div>
*
* @return the name for the Tortoise
*/
public static String getName()
{
return turtle().getName();
}
/**
* Sets the name for the tortoise
* <div><b>Example:</b> {@code Tortoise.setName("Ada Lovelace")}</div>
*
* @param name
* The name for the Tortoise
*/
public static void setName(String name)
{
turtle().setName(name);
}
/**
* Gets the speed that the tortoise moves
* <div><b>Example:</b> {@code int speed = Tortoise.getSpeed(8);}</div>
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/teachingextensions/logo/Turtle.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Turtle
{
public static final int TEST_SPEED = Integer.MIN_VALUE;
private static final double MAX_MOVE_AMOUNT = 5.0;
private String DEFAULT_NAME = "Grace Hopper";
public TurtleWindow panel = new TurtleWindow();
public List<LineSegment> trail = new ArrayList<LineSegment>();
private double x = 640 / 2;
Expand All @@ -40,6 +41,7 @@ public class Turtle
private boolean hidden;
private Animals animal;
private Sound sound = new Sound();
private String name = DEFAULT_NAME;
public BufferedImage getImage()
{
BufferedImage image = panel.getWindowImage();
Expand Down Expand Up @@ -133,6 +135,21 @@ private long getDelay()
if (getSpeed() == TEST_SPEED) { return TEST_SPEED; }
return 100 / getSpeed();
}
public String getName()
{
return name;
}
/**
* Sets the name for a turtle instance
* <p><b>Example:</b> {@code myTurtle.setName(name)}</p>
*
* @param name
* Your turtle's name
*/
public void setName(String name)
{
this.name = name;
}
public int getSpeed()
{
return speed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.teachingkidsprogramming.recipes.completed.section00demos;

import org.teachingextensions.logo.Tortoise;
import org.teachingextensions.logo.utils.EventUtils.MessageBox;

public class QuickTortoise
{
Expand All @@ -9,5 +10,8 @@ public static void main(String[] args) throws Exception
Tortoise.show();
// Use the Tortoise object to draw a Tortoise!
Tortoise.drawTortoise();
Tortoise.setName("Sam");
String t = (Tortoise.getName());
MessageBox.showMessage(t);
}
}

0 comments on commit bb03ad1

Please sign in to comment.