Skip to content

Commit ad716d0

Browse files
committed
Merge remote-tracking branch 'TeachingKidsProgramming/master'
2 parents 214c3e0 + 49b5f88 commit ad716d0

8 files changed

Lines changed: 345 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.teachingkidsprogramming.recipes.completed.section01forloops;
2+
3+
import org.teachingextensions.logo.Tortoise;
4+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
5+
6+
//
7+
//------------Kata Question---------------//
8+
// How would you make a triangle?
9+
// Write out the steps in English
10+
// Then translate the steps into code
11+
// Make sure to run after each line
12+
//
13+
public class SimpleSquareKataQuestion
14+
{
15+
public static void main(String[] args) throws Exception
16+
{
17+
Tortoise.show();
18+
Tortoise.setSpeed(10);
19+
for (int i = 0; i < 4; i++)
20+
{
21+
Tortoise.setPenColor(PenColors.Blues.Blue);
22+
Tortoise.move(50);
23+
Tortoise.turn(90);
24+
}
25+
}
26+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.teachingkidsprogramming.recipes.completed.section02methods;
2+
3+
import org.teachingextensions.logo.Tortoise;
4+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
5+
6+
//
7+
//------------Kata Question---------------//
8+
// How would you make a slanted roof?
9+
// Write out the steps in English
10+
// Then translate the steps into code
11+
// Make sure to run after each line
12+
//
13+
public class HousesKataQuestion
14+
{
15+
public static void main(String[] args)
16+
{
17+
Tortoise.show();
18+
Tortoise.setSpeed(10);
19+
Tortoise.setX(200);
20+
int height = 40;
21+
drawHouse(height);
22+
drawHouse(120);
23+
drawHouse(90);
24+
drawHouse(20);
25+
}
26+
public static void drawHouse(int height)
27+
{
28+
Tortoise.setPenColor(PenColors.Grays.LightGray);
29+
Tortoise.move(height);
30+
Tortoise.turn(90);
31+
Tortoise.move(30);
32+
Tortoise.turn(90);
33+
Tortoise.move(height);
34+
Tortoise.turn(-90);
35+
Tortoise.move(20);
36+
Tortoise.turn(-90);
37+
}
38+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs;
2+
3+
import java.awt.Toolkit;
4+
5+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
6+
7+
//
8+
//------------Kata Question---------------//
9+
// How would you make sure the guess is a positive number?
10+
// Write out the steps in English
11+
// Then translate the steps into code
12+
// Make sure to run after each line
13+
//
14+
public class HiLowKataQuestion
15+
{
16+
public static void main(String[] args)
17+
{
18+
// Choose a random number between 1 and 100 --#4.1 (fake!) & --#13 ***Math does not permit the generation of a random number between an interval
19+
//int answer = NumberUtils.getRandomInt(1, 100);
20+
int answer = 12;
21+
for (int i = 0; i < 8; i++)
22+
{
23+
int guess = MessageBox.askForNumericalInput("Can you guess the random number between 1 and 100?");
24+
if (guess == answer)
25+
{
26+
Toolkit.getDefaultToolkit().beep();
27+
MessageBox.showMessage("You won!");
28+
System.exit(0);
29+
}
30+
else if (guess > answer)
31+
{
32+
MessageBox.showMessage("Try a lower number.");
33+
}
34+
else if (guess < answer)
35+
{
36+
MessageBox.showMessage("Try a higher number.");
37+
}
38+
}
39+
MessageBox.showMessage("You lost!");
40+
}
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.teachingkidsprogramming.recipes.completed.section04mastery;
2+
3+
import java.awt.Color;
4+
5+
import org.teachingextensions.logo.Tortoise;
6+
import org.teachingextensions.logo.utils.ColorUtils.ColorWheel;
7+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
8+
9+
//
10+
//------------Kata Question---------------//
11+
// How would you change the shape of a flower petal?
12+
// Write out the steps in English
13+
// Then translate the steps into code
14+
// Make sure to run after each line
15+
//
16+
public class DigiFlowerKataQuestion
17+
{
18+
public static void main(String[] args)
19+
{
20+
Tortoise.show();
21+
Tortoise.setSpeed(10);
22+
Tortoise.getBackgroundWindow().setBackground(PenColors.Grays.Silver);
23+
Tortoise.setPenWidth(3);
24+
createColorPalette();
25+
for (int i = 0; i < 15; i++)
26+
{
27+
drawOctogon();
28+
Tortoise.turn(360.0 / 15);
29+
}
30+
}
31+
private static void createColorPalette()
32+
{
33+
Color color1 = PenColors.Reds.Red;
34+
Color color2 = PenColors.Oranges.DarkOrange;
35+
Color color3 = PenColors.Yellows.Gold;
36+
Color color4 = PenColors.Yellows.Yellow;
37+
ColorWheel.addColor(color1);
38+
ColorWheel.addColor(color2);
39+
ColorWheel.addColor(color3);
40+
ColorWheel.addColor(color4);
41+
ColorWheel.addColor(color4);
42+
ColorWheel.addColor(color3);
43+
ColorWheel.addColor(color2);
44+
ColorWheel.addColor(color1);
45+
}
46+
private static void drawOctogon()
47+
{
48+
for (int i = 0; i < 8; i++)
49+
{
50+
Tortoise.setPenColor(ColorWheel.getNextColor());
51+
Tortoise.move(50);
52+
Tortoise.turn(360.0 / 8);
53+
}
54+
}
55+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.teachingkidsprogramming.recipes.completed.section05recursion;
2+
3+
import java.awt.Color;
4+
import java.util.HashMap;
5+
6+
import org.teachingextensions.logo.Tortoise;
7+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
8+
9+
//
10+
//------------Kata Question---------------//
11+
//How would you add a second tree?
12+
//Write out the steps in English
13+
//Then translate the steps into code
14+
//Make sure to run after each line
15+
//
16+
public class TurtleTreeKataQuestion
17+
{
18+
public static void main(String[] args)
19+
{
20+
Tortoise.show();
21+
Tortoise.setSpeed(10);
22+
Tortoise.getBackgroundWindow().setBackground(PenColors.Grays.Black);
23+
int branchLength = 60;
24+
drawBranch(branchLength);
25+
}
26+
public static void drawBranch(int branchLength)
27+
{
28+
if (branchLength > 0)
29+
{
30+
adjustColor(branchLength);
31+
Tortoise.move(branchLength);
32+
drawLowerBranches(branchLength);
33+
}
34+
}
35+
public static void adjustColor(int branchLength)
36+
{
37+
HashMap<Integer, Color> colors = new HashMap<Integer, Color>();
38+
colors.put(10, PenColors.Greens.Lime);
39+
colors.put(20, PenColors.Greens.ForestGreen);
40+
colors.put(30, PenColors.Greens.DarkGreen);
41+
colors.put(40, PenColors.Greens.Olive);
42+
colors.put(50, PenColors.Browns.Sienna);
43+
colors.put(60, PenColors.Browns.SaddleBrown);
44+
Tortoise.setPenColor(colors.get(branchLength));
45+
}
46+
public static void drawLowerBranches(int branchLength)
47+
{
48+
Tortoise.turn(30);
49+
drawShorterBranches(branchLength);
50+
Tortoise.turn(-60);
51+
drawShorterBranches(branchLength);
52+
Tortoise.turn(30);
53+
adjustColor(branchLength);
54+
Tortoise.move(-branchLength);
55+
}
56+
public static void drawShorterBranches(int branchLength)
57+
{
58+
drawBranch(branchLength - 10);
59+
}
60+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.teachingkidsprogramming.recipes.completed.section06modelviewcontroller;
2+
3+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
4+
5+
//
6+
//------------Kata Question---------------//
7+
// How would you make sure that a number was NOT entered in the story?
8+
// Write out the steps in English
9+
// Then translate the steps into code
10+
// Make sure to run after each line
11+
//
12+
public class AdLibsKataQuestion
13+
{
14+
public static void main(String[] args)
15+
{
16+
String currentAdverb = MessageBox.askForTextInput("What is the adverb?");
17+
String currentEdVerb = MessageBox.askForTextInput("What is the -ed verb?");
18+
String currentBodyPart = MessageBox.askForTextInput("What is the body part?");
19+
String currentStory = "Today ";
20+
currentStory = currentStory + "I woke " + currentAdverb + ". ";
21+
currentStory = currentStory + "Then I " + currentEdVerb + " ";
22+
currentStory = currentStory + "my " + currentBodyPart + ". ";
23+
MessageBox.showMessage(currentStory);
24+
}
25+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.teachingkidsprogramming.recipes.completed.section07objects;
2+
3+
import org.teachingextensions.WindowUtils.MultiTurtleWindow;
4+
import org.teachingextensions.logo.Turtle;
5+
6+
//
7+
//------------Kata Question---------------//
8+
// How would you add a sound when the crazy turtle draws lightning?
9+
// Write out the steps in English
10+
// Then translate the steps into code
11+
// Make sure to run after each line
12+
//
13+
public class SuperTurtlesKataQuestion
14+
{
15+
public MultiTurtleWindow mtw = new MultiTurtleWindow();
16+
public SuperTurtlesKataQuestion()
17+
{
18+
showSomeTurtles();
19+
}
20+
public static void main(String[] args)
21+
{
22+
new SuperTurtlesKataQuestion();
23+
}
24+
private void showSomeTurtles()
25+
{
26+
makeSpeedyTurtle();
27+
makeSlowTurtle();
28+
makeCrazyTurtle();
29+
}
30+
private void makeSpeedyTurtle()
31+
{
32+
Turtle speedyTurtle = new Turtle();
33+
mtw.addAndShowTurtle(speedyTurtle);
34+
speedyTurtle.setSpeed(10);
35+
speedyTurtle.drawTriangle(100);
36+
}
37+
private void makeSlowTurtle()
38+
{
39+
Turtle slowTurtle = new Turtle();
40+
mtw.addAndShowTurtle(slowTurtle);
41+
slowTurtle.drawTriangle(-50);
42+
}
43+
private void makeCrazyTurtle()
44+
{
45+
Turtle crazyTurtle = new Turtle();
46+
mtw.addTurtle(crazyTurtle);
47+
crazyTurtle.drawLightning(55);
48+
}
49+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.teachingkidsprogramming.recipes.completed.section08events;
2+
3+
import org.teachingextensions.WindowUtils.ProgramWindow;
4+
import org.teachingextensions.approvals.lite.util.NumberUtils;
5+
import org.teachingextensions.logo.utils.ColorUtils.ColorWheel;
6+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
7+
import org.teachingextensions.logo.utils.EventUtils.MouseLeftClickListener;
8+
import org.teachingextensions.logo.utils.LineAndShapeUtils.Circle;
9+
10+
//
11+
//------------Kata Question---------------//
12+
// How would you change your bubble into a unicorn when you right click on the window?
13+
// Write out the steps in English
14+
// Then translate the steps into code
15+
// Make sure to run after each line
16+
//
17+
public class SimpleBubbleKataQuestion implements MouseLeftClickListener
18+
{
19+
private ProgramWindow programWindow;
20+
public SimpleBubbleKataQuestion()
21+
{
22+
programWindow = new ProgramWindow("My Bubble");
23+
programWindow.setWindowVisible(true);
24+
programWindow.addMouseLeftClickListener(this);
25+
prepareColorPalette();
26+
}
27+
private void prepareColorPalette()
28+
{
29+
ColorWheel.addColor(PenColors.Blues.LightSteelBlue);
30+
ColorWheel.addColor(PenColors.Blues.Blue);
31+
ColorWheel.addColor(PenColors.Blues.DarkBlue);
32+
ColorWheel.addColor(PenColors.Purples.Purple);
33+
}
34+
@Override
35+
public void onLeftMouseClick(int x, int y)
36+
{
37+
createBubble(x, y);
38+
}
39+
private void createBubble(int x, int y)
40+
{
41+
programWindow.removePaintable();
42+
int radius = NumberUtils.getRandomInt(10, 50);
43+
Circle circle = new Circle(radius, ColorWheel.getNextColor());
44+
circle.setCenter(x, y);
45+
circle.addTo(programWindow);
46+
}
47+
public static void main(String[] args)
48+
{
49+
new SimpleBubbleKataQuestion();
50+
}
51+
}

0 commit comments

Comments
 (0)