Skip to content

Commit d380470

Browse files
committed
new recipe TurtleObjects
1 parent 9442c17 commit d380470

3 files changed

Lines changed: 44 additions & 67 deletions

File tree

src/main/java/org/teachingextensions/logo/Turtle.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ public void moveSynchronized(int x, int y)
292292
move(distance);
293293
}
294294
/**
295-
* Draws a triangle of a specified size
295+
* Draws a triangle of a specified size and orientation
296296
* <p><b>Example:</b> {@code myTurtle.drawTriangle(size)}</p>
297297
*
298298
* @param size
299-
* The size of a side of the triangle
299+
* The size of a side of the triangle, negative numbers draw an upside down triangle
300300
*/
301301
public void drawTriangle(int size)
302302
{
@@ -370,6 +370,13 @@ public Double save(Double save) throws SavingException
370370
return save;
371371
}
372372
}
373+
/**
374+
* Draws a lightning bolt of a specified length
375+
* <p><b>Example:</b> {@code myTurtle.drawLightning(length)}</p>
376+
*
377+
* @param length
378+
* The length of a lightning bolt
379+
*/
373380
public void drawLightning(int length)
374381
{
375382
this.setX(50);

src/main/java/org/teachingkidsprogramming/recipes/completed/section07objects/TurtleObjects.java

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,67 @@
66
public class TurtleObjects
77
{
88
public MultiTurtleWindow mtw = new MultiTurtleWindow();
9-
public static void main(String[] args)
10-
{
11-
new TurtleObjects();
12-
}
139
public TurtleObjects()
1410
{
1511
showSomeTurtles();
1612
}
17-
//
13+
public static void main(String[] args)
14+
{
15+
new TurtleObjects();
16+
}
1817
private void showSomeTurtles()
1918
{
19+
// Call the makeSpeedyTurtle method --#2
2020
makeSpeedyTurtle();
21+
// Call the makeSlowTurtle method --#4
2122
makeSlowTurtle();
23+
// Call the makeCrazyTurtle method --#6
2224
makeCrazyTurtle();
2325
}
26+
//
27+
// NOTE: Teacher to point out the mtw.addAndShowTurtle method
28+
// NOTE: Teacher to ask 'what are the steps of the drawTriangle method'?
29+
// Create the makeSpeedyTurtle method --#1.0
2430
private void makeSpeedyTurtle()
2531
{
32+
// Create a new speedyTurtle instance
2633
Turtle speedyTurtle = new Turtle();
34+
// Set the speed of your speedyTurtle to the fastest possible
2735
speedyTurtle.setSpeed(10);
36+
// Add your speedyTurtle to your MultiTurtleWindow
2837
mtw.addAndShowTurtle(speedyTurtle);
38+
// Have your speedyTurtle draw a triangle with 100 pixel sides
2939
speedyTurtle.drawTriangle(100);
40+
// End of makeSpeedyTurtle method --#1.1
3041
}
42+
//
43+
// NOTE: Teacher to ask why this turtle is slower than the first one
44+
// NOTE: Teacher to ask why the two turtles start at the same spot
45+
// Create the makeSlowTurtle method --#3.0
3146
private void makeSlowTurtle()
3247
{
48+
// Create a new slowTurtle instance
3349
Turtle slowTurtle = new Turtle();
50+
// Add your slowTurtle to your MultiTurtleWindow
3451
mtw.addAndShowTurtle(slowTurtle);
52+
// Have your slowTurtle draw a upside down triangle with 50 pixel sides
3553
slowTurtle.drawTriangle(-50);
54+
// End of makeSlowTurtle method --#3.1
3655
}
56+
//
57+
// NOTE: Teacher to ask why is this turtle faster than the second one
58+
// NOTE: Teacher to ask why does this turtle 'start' in a different location
59+
// NOTE: Teacher to ask why does this turtle show up AFTER the other two HINT: mtw.addTurtle method
60+
// NOTE: Teacher to ask what does the drawLightning method do?
61+
// Create the makeCrazyTurtle method --#5.0
3762
private void makeCrazyTurtle()
3863
{
64+
// Create a new crazyTurtle instance
3965
Turtle crazyTurtle = new Turtle();
66+
// Add your crazyTurtle to your MultiTurtleWindow
4067
mtw.addTurtle(crazyTurtle);
68+
// Have your crazyTurtle draw a 55 pixel long lightning bolt
4169
crazyTurtle.drawLightning(55);
70+
// End of makeCrazyTurtle method --#5.1
4271
}
43-
}
72+
}

src/main/java/org/teachingkidsprogramming/section07objects/TurtleObjects.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)