Skip to content

Commit 4d18b9a

Browse files
committed
working on 'Pyramids of Giza' w/@dcoopersmith
1 parent 71b499b commit 4d18b9a

5 files changed

Lines changed: 129 additions & 40 deletions

File tree

src/main/java/org/teachingkidsprogramming/recipes/inDevelopment/PyramidsOfGiza.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,21 @@
11
package org.teachingkidsprogramming.recipes.inDevelopment;
22

33
import org.teachingextensions.logo.Tortoise;
4-
//
5-
// 1. This recipe written in linear fashion with lots of repeated code
6-
// 2. a) turnAndMove() method created
7-
// b) every 2 linear turn() and move() calls are replaced by 1 call to new turnAndMove() method
8-
// 3. Now another pattern emerges, and a 3rd refactoring/abstraction takes place
9-
// when the student notices that there are several each of
10-
// turnAndMove(90, 100) & turnAndMove(-90, 100), so 2 new methods are written:
11-
// turnAndMove(90, 100) becomes -> moveDown() & turnAndMove(-90, 100) -> moveUp()
12-
// 4. At this point, students are encouraged to see if there might be any other possible patterns
13-
// to refactor
144

15-
// Where to add? In Course 1 or Course 2 - concepts taught: method arguments (variables) and refactoring
165
public class PyramidsOfGiza
176
{
7+
/*----IN PROGRESS-----------------------------------*/
188
public static void main(String[] args) throws Exception
199
{
2010
Tortoise.show();
2111
Tortoise.setSpeed(10);
2212
turnAndMove(-90, 220);
23-
// Tortoise.turn(-90);
24-
// Tortoise.move(220);
2513
turnAndMove(135, 100);
26-
// Tortoise.turn(135);
27-
// Tortoise.move(100);
2814
moveDown();
29-
// turnAndMove(90, 100);
30-
// Tortoise.turn(90);
31-
// Tortoise.move(100);
3215
moveUp();
33-
// turnAndMove(-90, 100);
34-
// Tortoise.turn(-90);
35-
// Tortoise.move(100);
3616
moveDown();
37-
// turnAndMove(90, 100);
38-
// Tortoise.turn(90);
39-
// Tortoise.move(100);
4017
moveUp();
41-
//turnAndMove(-90, 100);
42-
// Tortoise.turn(-90);
43-
// Tortoise.move(100);
4418
moveDown();
45-
// turnAndMove(90, 100);
46-
// Tortoise.turn(90);
47-
// Tortoise.move(100);
4819
Tortoise.turn(135);
4920
Tortoise.move(210);
5021
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.teachingkidsprogramming.recipes.inDevelopment;
2+
3+
import org.teachingextensions.logo.Tortoise;
4+
//
5+
// 1. This recipe written in linear fashion with lots of repeated code
6+
// 2. a) turnAndMove() method created
7+
// b) every 2 linear turn() and move() calls are replaced by 1 call to new turnAndMove() method
8+
// 3. Now another pattern emerges, and a 3rd refactoring/abstraction takes place
9+
// when the student notices that there are several each of
10+
// turnAndMove(90, 100) & turnAndMove(-90, 100), so 2 new methods are written:
11+
// turnAndMove(90, 100) becomes -> moveDown() & turnAndMove(-90, 100) -> moveUp()
12+
// 4. At this point, students are encouraged to see if there might be any other possible patterns
13+
// to refactor
14+
15+
// Where to add? In Course 1 or Course 2 - concepts taught: method arguments (variables) and refactoring
16+
public class PyramidsOfGizaMiddle
17+
{
18+
/*----IN PROGRESS-----------------------------------*/
19+
public static void main(String[] args) throws Exception
20+
{
21+
Tortoise.show();
22+
Tortoise.setSpeed(10);
23+
turnAndMove(-90, 220);
24+
// Tortoise.turn(-90);
25+
// Tortoise.move(220);
26+
turnAndMove(135, 100);
27+
// Tortoise.turn(135);
28+
// Tortoise.move(100);
29+
moveDown();
30+
// turnAndMove(90, 100);
31+
// Tortoise.turn(90);
32+
// Tortoise.move(100);
33+
moveUp();
34+
// turnAndMove(-90, 100);
35+
// Tortoise.turn(-90);
36+
// Tortoise.move(100);
37+
moveDown();
38+
// turnAndMove(90, 100);
39+
// Tortoise.turn(90);
40+
// Tortoise.move(100);
41+
moveUp();
42+
//turnAndMove(-90, 100);
43+
// Tortoise.turn(-90);
44+
// Tortoise.move(100);
45+
moveDown();
46+
// turnAndMove(90, 100);
47+
// Tortoise.turn(90);
48+
// Tortoise.move(100);
49+
Tortoise.turn(135);
50+
Tortoise.move(210);
51+
}
52+
public static void moveDown()
53+
{
54+
turnAndMove(90, 100);
55+
}
56+
public static void moveUp()
57+
{
58+
turnAndMove(-90, 100);
59+
}
60+
public static void turnAndMove(int degrees, int length)
61+
{
62+
Tortoise.turn(degrees);
63+
Tortoise.move(length);
64+
}
65+
}

src/main/java/org/teachingkidsprogramming/recipes/inDevelopment/PyramidsOfGizaStarter.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@
44

55
public class PyramidsOfGizaStarter
66
{
7+
/*----IN PROGRESS-----------------------------------*/
78
public static void main(String[] args) throws Exception
89
{
9-
setupTortoise();
10-
// USER STORY: Write the code to draw 3 pyramids
11-
// Draw a sketch
12-
// Write out each step in English
13-
// Write the code one line at a time
14-
// Run your program to verify that your code works
15-
// Remove duplicate code by using the 'extract method' re-factoring
16-
}
17-
private static void setupTortoise()
18-
{
10+
// Show the tortoise
1911
Tortoise.show();
2012
Tortoise.setSpeed(10);
13+
Tortoise.turn(-90);
14+
Tortoise.move(220);
15+
Tortoise.turn(135);
16+
Tortoise.move(100);
17+
Tortoise.turn(90);
18+
Tortoise.move(100);
19+
Tortoise.turn(-90);
20+
Tortoise.move(100);
21+
Tortoise.turn(90);
22+
Tortoise.move(100);
23+
Tortoise.turn(-90);
24+
Tortoise.move(100);
25+
Tortoise.turn(90);
26+
Tortoise.move(100);
27+
Tortoise.turn(135);
28+
Tortoise.move(210);
2129
}
2230
}
31+
/*
32+
// Show the tortoise --#1
33+
// Make the tortoise move as fast as possible --#6
34+
// Do the following 4 times --#5.1
35+
// Change the pen color of the line the tortoise draws to blue --#4
36+
// Move the tortoise 50 pixels --#2
37+
// Turn the tortoise to the right (90 degrees) --#3
38+
// Repeat --#5.2
39+
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.teachingkidsprogramming.recipes.inDevelopment;
2+
3+
public class firstKata
4+
{
5+
public static void main(String[] args) throws Exception
6+
{
7+
//Requirement: Write the USER STORIES to draw 3 pyramids
8+
// Draw a sketch
9+
// Decompose the sketch into one or more user stories
10+
// Write out each step in English
11+
// for example (create one pyramid, create one side)
12+
// optionally write each user story on a post it
13+
// use a Kanban board with 'ToDo', 'Doing', 'Done'
14+
// Select the simplest user story than can be verified
15+
// Write the English, write the code and run the code
16+
// Does your code do what you expected?
17+
// Continue
18+
// Write the code one line at a time
19+
// Run your program to verify that your code works
20+
// Part Two - when you are 'done' look at your code - are there duplicate lines
21+
// Remove duplicate code by using the 'extract method' re-factoring
22+
// Understand how to pass multiple arguments to a method
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.teachingkidsprogramming.recipes.inDevelopment;
2+
3+
public class forLoopUpdate
4+
{
5+
public static void main(String[] args) throws Exception
6+
{
7+
// Input from Brick Ellis
8+
// Update 'for loop English syntax'
9+
// End of loop s/b 'end repeat'
10+
// Refer to 'for loop ' as 'this <item>' with a noun
11+
}
12+
}

0 commit comments

Comments
 (0)