Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.teachingkidsprogramming.recipes;

public class FizzBuzz
{
public static String convert(int i)
{
if (i % 15 == 0) { return "FizzBuzz"; }
if (i % 3 == 0) { return "Fizz"; }
if (i % 5 == 0)
{
return "Buzz";
}
else
{
return "" + i;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.teachingkidsprogramming.recipes;

import org.junit.Assert;
import org.junit.Test;

public class FizzBuzzTest
{
@Test
public void test1Produces1()
{
Assert.assertEquals("1", FizzBuzz.convert(1));
}
@Test
public void test2Produces2()
{
Assert.assertEquals("2", FizzBuzz.convert(2));
}
@Test
public void test3ProducesFizz()
{
Assert.assertEquals("Fizz", FizzBuzz.convert(3));
}
@Test
public void test4Produces4()
{
Assert.assertEquals("4", FizzBuzz.convert(4));
}
@Test
public void testMultiplesof3ProducesFizz()
{
Assert.assertEquals("Fizz", FizzBuzz.convert(6));
}
@Test
public void test5ProducesBuzz()
{
Assert.assertEquals("Buzz", FizzBuzz.convert(5));
}
@Test
public void testMultipleof5ProducesBuzz()
{
Assert.assertEquals("Buzz", FizzBuzz.convert(10));
}
@Test
public void testMultipleof15ProducesFizzBuzz()
{
Assert.assertEquals("FizzBuzz", FizzBuzz.convert(15));
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package org.teachingkidsprogramming.recipes;

import org.teachingextensions.logo.ColorWheel;
import org.teachingextensions.logo.Colors.Purples;
import org.teachingextensions.logo.Tortoise;

public class Spiral
{
public static void main(String[] args)
{
// Show the tortoise --#1
// Make the tortoise go as fast as possible --#4
// Add Blue Violet to the Color Wheel --#6
// Add Violet to the Color Wheel --#8
// Add Purple to the Color Wheel --#9
// Do the following 75 times --#3
// Change the color of the line the tortoise draws the next color on the Color Wheel --#7
// Move the tortoise 5 times the current line number you are drawing --#5
// Turn the tortoise 1/3 of 360 degrees to the right --#2
//colorwheel
ColorWheel.addColor(Purples.BlueViolet);
ColorWheel.addColor(Purples.Violet);
ColorWheel.addColor(Purples.Purple);
//default code
Tortoise.show();
Tortoise.setSpeed(10);
int linenumber = 0;
//drawing
for (int i = 1; i <= 75; i++)
{
Tortoise.setPenColor(ColorWheel.getNextColor());
Tortoise.move(5 * linenumber++);
Tortoise.turn(360 / 3);
}
}
private static void linenumber()
{
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,79 @@
package org.teachingkidsprogramming.recipes;

import org.teachingextensions.logo.Colors;
import org.teachingextensions.logo.Turtle;

import com.spun.util.NumberUtils;

public class TurtleTree
{
public static void main(String[] args)
{
// Make the tortoise go as fast as possible --#11
// Turn the background black --#22
// The current branch length = 60 --#1.2
// drawBranch(recipe below) --#2
// ------------- Recipe for drawBranch --#2
// If the current branch length is greater than zero, do the rest of this recipe --#6
// adjustColor --#16
// ------------- Recipe for adjustColor --#16
// A 10 pixel long branch is lime --#21
// A 20 pixel long branch is forest green --#20
// A 30 pixel long branch is dark green --#19
// A 40 pixel long branch is olive --#18
// A 50 pixel long branch is sienna --#15
// A 60 pixel long branch is saddle brown --#14
// ------------- End of adjustColor --#16
// Move the tortoise the length of the current branch --#1.1
// drawLowerBranches (recipe below) --#7
// ------------- Recipe for drawLowerBranches --#7
// Turn the Tortoise 30 degrees to the right --#3
// drawShorterBranch (recipe below) --#9
// ------------- Recipe for drawShorterBranch --#9
// drawBranch (10 pixels shorter) --#4
// ------------- End of drawShorterBranch recipe --#9
// Turn the Tortoise 60 degrees to the left --#8
// drawShorterBranch --#10
// Turn the Tortoise 30 degrees to the right --#13
// adjustColor --#17
// Move the tortoise backward the length of the current branch --#12
// ------------- End of drawLowerBranches recipe --#7
// ------------- End of drawBranch recipe --#2
Turtle turtle = new Turtle();
// lower the y-coordinate by 100
turtle.setY(turtle.getY() - (100));
turtle.setSpeed(10);
turtle.getBackgroundWindow().setBackground(Colors.Grays.Black);
int length = 60;
drawBranch(turtle, length);
}
private static void drawBranch(Turtle turtle, int length)
{
if (0 < length)
{
adjustColor(turtle, length);
turtle.move(length);
drawLowerBranches(turtle, length);
}
}
private static void adjustColor(Turtle turtle, int length)
{
if (length <= 10)
{
turtle.setPenWidth(2);
turtle.setPenColor(Colors.Pinks.LightPink);
}
else if (length <= 20)
{
turtle.setPenWidth(3);
turtle.setPenColor(Colors.Pinks.HotPink);
}
else if (length <= 30)
{
turtle.setPenWidth(5);
turtle.setPenColor(Colors.Pinks.DeepPink);
}
else if (length <= 40)
{
turtle.setPenWidth(6);
turtle.setPenColor(Colors.Reds.Salmon);
}
else if (length <= 50)
{
turtle.setPenWidth(8);
turtle.setPenColor(Colors.Reds.Red);
}
else if (length <= 60)
{
turtle.setPenColor(Colors.Reds.FireBrick);
turtle.setPenWidth(10);
}
}
private static void drawLowerBranches(Turtle turtle, int length)
{
int rightangle = NumberUtils.getRandomInt(20, 40);
turtle.turn(rightangle);
drawShorterBranch(turtle, length);
int leftangle = NumberUtils.getRandomInt(10, 60);
turtle.turn(leftangle - rightangle);
drawShorterBranch(turtle, length);
turtle.turn(-leftangle);
adjustColor(turtle, length);
turtle.move(-length);
}
private static void drawShorterBranch(Turtle turtle, int length)
{
int difference = NumberUtils.getRandomInt(10, 30);
drawBranch(turtle, length - difference);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.teachingkidsprogramming.recipes.finalExam;

import org.teachingextensions.logo.Colors;
import org.teachingextensions.logo.Tortoise;
import org.teachingextensions.windows.MessageBox;

public class ExamTriangleShellOne
{
private static int length;
public static void main(String[] args)
{
Tortoise.show();
Tortoise.setSpeed(10);
int shellSize = MessageBox.askForNumericalInput("Pick a number.");
if (shellSize < 200)
{
MessageBox.askForNumericalInput("Size of the shell is too small to be seen" + "...So pick a bigger number.");
}
else
{
for (int i = 1; i <= shellSize; i++)
{
Tortoise.setPenColor(Colors.getRandomColor());
// Set the value of the large length to the size of the shell divided by 100
int largeLength = length / 100;
// Add the value of the large length to the current length
parse largeLength = length;
}
// If the value of the large length is less than zero
{
// Set the value of the length to the length plus 3
// Otherwise, Call the drawTriangle method (recipe below)
// Set the value of the number of rotations to 6
// Turn the tortoise 360 times the number of rotations, then divide that by the size of the shell
}
}
// Repeat
}
//------------- Recipe for drawTriangle
// Do the following 2.5 times
// Move the tortoise the current length
// Turn the tortoise 1/3.5 of 360 degrees
// Repeat
//------------- End of drawTriangle recipe
}
Loading