Skip to content

Commit 8d0c858

Browse files
committed
Added new recipe ManyAnimals w/Jim
1 parent 0653fd6 commit 8d0c858

6 files changed

Lines changed: 76 additions & 67 deletions

File tree

.classpath

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="src" path="section08tdd"/>
5-
<classpathentry kind="src" path="section09Exceptions"/>
6-
<classpathentry kind="src" path="PrintThis"/>
74
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
85
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
96
<classpathentry combineaccessrules="false" kind="src" path="/ApprovalTests"/>

src/org/teachingextensions/setup/SetupConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
public class SetupConfig
99
{
1010
public ValidationError setup = new ValidationError(SetupCheckPoints.values());
11-
public String workspacePath = "."; //"C:\\Users\\Llewellyn\\workspace\\ApprovalTestsKoans\\TeachingKidsProgramming.Java";
11+
public String workspacePath = ".";
12+
//"C:\\Users\\Llewellyn\\workspace\\ApprovalTestsKoans\\TeachingKidsProgramming.Java";
1213
public String eclipsePath = SystemUtils.isWindowsEnviroment()
1314
? eclipsePathWindows
1415
: eclipsePathMac;

src/org/teachingkidsprogramming/recipes/completed/ConnectTheDots.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ConnectTheDots implements MouseRightClickListener, MouseLeftClickLi
1414
{
1515
public static void main(String[] args)
1616
{
17-
//Create new a 'Connect the Dots' window.
17+
//Create new a 'Connect the Dots' object.
1818
ConnectTheDots dots = new ConnectTheDots();
1919
}
2020
public ConnectTheDots()
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.teachingkidsprogramming.recipes.completed;
2+
3+
import java.util.ArrayList;
4+
5+
import org.teachingextensions.logo.MultiTurtlePanel;
6+
import org.teachingextensions.logo.Turtle;
7+
8+
public class ManyAnimals
9+
{
10+
public ManyAnimals()
11+
{
12+
showSomeTurtles();
13+
}
14+
//create container for Turtles HINT: Use ArrayList
15+
public ArrayList<Turtle> turtles = new ArrayList<Turtle>();
16+
//create a window for many turtles HINT: Use MultiTurtlePanel
17+
public MultiTurtlePanel mt = new MultiTurtlePanel();
18+
private void showSomeTurtles()
19+
{
20+
//show the panel
21+
mt.showPanel();
22+
//set the size to 100
23+
int size = 100;
24+
//add three turtles HINT: FOR loop which 'does an action'
25+
for (int i = 1; i <= 3; i++)
26+
{
27+
//create a turtle
28+
Turtle turtle = new Turtle();
29+
//add the turtles to the container for turtles
30+
turtles.add(turtle);
31+
}
32+
//add all turtles to the window HINT: Use a foreach loop
33+
for (Turtle turtle : turtles)
34+
{
35+
//NOTE: must call addTurtle BEFORE calling other methods
36+
//add all turtles to the window
37+
mt.addTurtle(turtle);
38+
}
39+
//teleport all turtles on the window HINT: Use a FOR loop and ZERO
40+
for (int i = 0; i < 3; i++)
41+
{
42+
//set the X position to i*100 + 350
43+
turtles.get(i).setX(i * 100 + 350);
44+
//set the Y position to i*100 + 100
45+
turtles.get(i).setY(i * 100 + 100);
46+
}
47+
//set some values for all turtles HINT: Use a foreach loop
48+
for (Turtle turtle : turtles)
49+
{
50+
//set the speed of all turtle's to 7
51+
turtle.setSpeed(7);
52+
//have every turtle draw a star of the current size
53+
turtle.drawStar(size);
54+
}
55+
}
56+
public static void main(String[] args)
57+
{
58+
new ManyAnimals();
59+
}
60+
}

src/org/teachingkidsprogramming/section07events/ConnectTheDots.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class ConnectTheDots implements MouseRightClickListener, MouseLeftClickLi
77
{
88
public static void main(String[] args)
99
{
10-
//Create a new 'Connect The Dots' window. --#1.1
10+
//Create a new 'Connect The Dots' object. --#1.1
1111
}
1212
public ConnectTheDots()
1313
{

src/org/teachingkidsprogramming/section07events/ManyAnimals.java

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,29 @@
11
package org.teachingkidsprogramming.section07events;
22

3-
import java.util.ArrayList;
4-
5-
import org.teachingextensions.logo.MultiTurtlePanel;
6-
import org.teachingextensions.logo.Turtle;
7-
import org.teachingextensions.windows.MouseLeftClickListener;
8-
9-
public class ManyAnimals implements MouseLeftClickListener
3+
public class ManyAnimals
104
{
115
public ManyAnimals()
126
{
137
showSomeTurtles();
148
}
159
//create container for Turtles HINT: Use ArrayList
16-
public ArrayList<Turtle> turtles = new ArrayList<Turtle>();
1710
//create a window for many turtles HINT: Use MultiTurtlePanel
18-
public MultiTurtlePanel mt = new MultiTurtlePanel();
1911
private void showSomeTurtles()
2012
{
2113
//show the panel
22-
mt.showPanel();
23-
//listen for left mouse button click
24-
//mt.addMouseLeftClickListener(this);
2514
//set the size to 100
26-
int size = 100;
27-
//add three turtles HINT: Use a For loop
28-
for (int i = 1; i <= 3; i++)
29-
{
30-
//create a turtle
31-
Turtle turtle = new Turtle();
32-
//add the turtles to the container for turtles
33-
turtles.add(turtle);
34-
}
35-
//add all turtles to the window HINT: Use a FOR loop
36-
for (Turtle turtle : turtles)
37-
{
38-
//NOTE: must call addTurtle BEFORE calling other methods
39-
//add all turtles to the window
40-
mt.addTurtle(turtle);
41-
}
15+
//add three turtles HINT: FOR loop which 'does an action'
16+
//create a turtle
17+
//add the turtles to the container for turtles
18+
//add all turtles to the window HINT: Use a foreach loop
19+
//NOTE: must call addTurtle BEFORE calling other methods
20+
//add all turtles to the window
4221
//teleport all turtles on the window HINT: Use a FOR loop and ZERO
43-
for (int i = 0; i < 3; i++)
44-
{
45-
//set the X position to i*100 + 350
46-
turtles.get(i).setX(i * 100 + 350);
47-
//set the Y position to i*100 + 100
48-
turtles.get(i).setY(i * 100 + 100);
49-
}
50-
//set some values for all turtles HINT: Use a FOR loop
51-
for (Turtle turtle : turtles)
52-
{
53-
//set the speed of all turtle's to 7
54-
turtle.setSpeed(7);
55-
//have every turtle draw a star of the current size
56-
turtle.drawStar(size);
57-
}
58-
}
59-
@Override
60-
//threading error - Virtual Proctor contention
61-
public void onLeftMouseClick(int x, int y)
62-
{
63-
int size = 200;
64-
//create a new Turtle
65-
Turtle turtle = new Turtle();
66-
//add another turtle to the turtles
67-
turtles.add(turtle);
68-
// the turtle to the window
69-
mt.addTurtle(turtle);
70-
turtle.show();
71-
// teleport the new turtle to the x and y of the mouse click
72-
turtle.setX(x);
73-
turtle.setY(y);
74-
// have this turtle draw a star
75-
turtle.drawStar(size);
22+
//set the X position to i*100 + 350
23+
//set the Y position to i*100 + 100
24+
//set some values for all turtles HINT: Use a foreach loop
25+
//set the speed of all turtle's to 7
26+
//have every turtle draw a star of the current size
7627
}
7728
public static void main(String[] args)
7829
{

0 commit comments

Comments
 (0)