Skip to content

Commit 9ec03e3

Browse files
committed
new kata questions for DigiGirlz Flower
1 parent cc77f1b commit 9ec03e3

File tree

6 files changed

+177
-68
lines changed

6 files changed

+177
-68
lines changed

src/main/java/org/teachingkidsprogramming/recipes/completed/section04mastery/KataQuestions/DigiFlower_01.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88

99
//
1010
//------------Kata Question---------------//
11-
// How would you change the shape of a flower petal?
12-
// Refactor the number of petals as a method
13-
// Refactor (rename) the petal-making method
14-
// Draw more than one flower
11+
// How can you easily change the shape of a flower petal?
12+
// Re factor the number of petals as a method
13+
// Re factor (rename) the petal-making method
1514
// Write out the steps in English
1615
// Then translate the steps into code
1716
// Make sure to run after each line
@@ -31,6 +30,15 @@ public static void main(String[] args)
3130
Tortoise.turn(360.0 / 15);
3231
}
3332
}
33+
private static void drawOctogon()
34+
{
35+
for (int i = 0; i < 8; i++)
36+
{
37+
Tortoise.setPenColor(ColorWheel.getNextColor());
38+
Tortoise.move(50);
39+
Tortoise.turn(360.0 / 8);
40+
}
41+
}
3442
private static void createColorPalette()
3543
{
3644
Color color1 = PenColors.Reds.Red;
@@ -46,13 +54,4 @@ private static void createColorPalette()
4654
ColorWheel.addColor(color2);
4755
ColorWheel.addColor(color1);
4856
}
49-
private static void drawOctogon()
50-
{
51-
for (int i = 0; i < 8; i++)
52-
{
53-
Tortoise.setPenColor(ColorWheel.getNextColor());
54-
Tortoise.move(50);
55-
Tortoise.turn(360.0 / 8);
56-
}
57-
}
5857
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section04mastery/KataQuestions/DigiFlower_02.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
//
1010
//------------Kata Question---------------//
11-
//How would you change the shape of a flower petal?
12-
//Refactor the number of petals as a method
13-
//Refactor (rename) the petal-making method
14-
//Draw more than one flower
11+
// How can you easily change the shape of a flower petal?
12+
// Re factor the loops variables
1513
//Write out the steps in English
1614
//Then translate the steps into code
1715
//Make sure to run after each line
@@ -35,6 +33,15 @@ private static void drawFlower()
3533
Tortoise.turn(360.0 / 15);
3634
}
3735
}
36+
private static void drawPetal()
37+
{
38+
for (int i = 0; i < 8; i++)
39+
{
40+
Tortoise.setPenColor(ColorWheel.getNextColor());
41+
Tortoise.move(50);
42+
Tortoise.turn(360.0 / 8);
43+
}
44+
}
3845
private static void createColorPalette()
3946
{
4047
Color color1 = PenColors.Reds.Red;
@@ -50,13 +57,4 @@ private static void createColorPalette()
5057
ColorWheel.addColor(color2);
5158
ColorWheel.addColor(color1);
5259
}
53-
private static void drawPetal()
54-
{
55-
for (int i = 0; i < 8; i++)
56-
{
57-
Tortoise.setPenColor(ColorWheel.getNextColor());
58-
Tortoise.move(50);
59-
Tortoise.turn(360.0 / 8);
60-
}
61-
}
6260
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section04mastery/KataQuestions/DigiFlower_03.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88

99
//
1010
//------------Kata Question---------------//
11-
//How would you change the shape of a flower petal?
12-
//Refactor the number of petals as a method
13-
//Refactor (rename) the petal-making method
14-
//Draw more than one flower
15-
//Write out the steps in English
16-
//Then translate the steps into code
17-
//Make sure to run after each line
11+
//How would you draw more than one flower?
1812
//
1913
public class DigiFlower_03
2014
{
@@ -26,15 +20,24 @@ public static void main(String[] args)
2620
Tortoise.setPenWidth(3);
2721
createColorPalette();
2822
drawFlower();
29-
Tortoise.move(200);
30-
drawFlower();
3123
}
3224
private static void drawFlower()
3325
{
34-
for (int i = 0; i < 15; i++)
26+
int numberOfPetals = 15;
27+
for (int i = 0; i < numberOfPetals; i++)
3528
{
3629
drawPetal();
37-
Tortoise.turn(360.0 / 15);
30+
Tortoise.turn(360.0 / numberOfPetals);
31+
}
32+
}
33+
private static void drawPetal()
34+
{
35+
int petalShape = 8;
36+
for (int i = 0; i < petalShape; i++)
37+
{
38+
Tortoise.setPenColor(ColorWheel.getNextColor());
39+
Tortoise.move(50);
40+
Tortoise.turn(360.0 / petalShape);
3841
}
3942
}
4043
private static void createColorPalette()
@@ -52,13 +55,4 @@ private static void createColorPalette()
5255
ColorWheel.addColor(color2);
5356
ColorWheel.addColor(color1);
5457
}
55-
private static void drawPetal()
56-
{
57-
for (int i = 0; i < 8; i++)
58-
{
59-
Tortoise.setPenColor(ColorWheel.getNextColor());
60-
Tortoise.move(50);
61-
Tortoise.turn(360.0 / 8);
62-
}
63-
}
6458
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section04mastery/KataQuestions/DigiFlower_04.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88

99
//
1010
//------------Kata Question---------------//
11-
//How would you change the shape of a flower petal?
12-
//Refactor the number of petals as a method
13-
//Refactor (rename) the petal-making method
14-
//Draw more than one flower
15-
//Write out the steps in English
16-
//Then translate the steps into code
17-
//Make sure to run after each line
11+
// How would you fix the position of more than one flower?
1812
//
1913
public class DigiFlower_04
2014
{
@@ -25,19 +19,27 @@ public static void main(String[] args)
2519
Tortoise.getBackgroundWindow().setBackground(PenColors.Grays.Silver);
2620
Tortoise.setPenWidth(3);
2721
createColorPalette();
28-
Tortoise.setX(150);
29-
Tortoise.setY(150);
3022
drawFlower();
31-
Tortoise.setX(400);
32-
Tortoise.setY(300);
23+
Tortoise.move(200);
3324
drawFlower();
3425
}
3526
private static void drawFlower()
3627
{
37-
for (int i = 0; i < 15; i++)
28+
int numberOfPetals = 15;
29+
for (int i = 0; i < numberOfPetals; i++)
3830
{
3931
drawPetal();
40-
Tortoise.turn(360.0 / 15);
32+
Tortoise.turn(360.0 / numberOfPetals);
33+
}
34+
}
35+
private static void drawPetal()
36+
{
37+
int petalShape = 8;
38+
for (int i = 0; i < petalShape; i++)
39+
{
40+
Tortoise.setPenColor(ColorWheel.getNextColor());
41+
Tortoise.move(50);
42+
Tortoise.turn(360.0 / petalShape);
4143
}
4244
}
4345
private static void createColorPalette()
@@ -55,13 +57,4 @@ private static void createColorPalette()
5557
ColorWheel.addColor(color2);
5658
ColorWheel.addColor(color1);
5759
}
58-
private static void drawPetal()
59-
{
60-
for (int i = 0; i < 8; i++)
61-
{
62-
Tortoise.setPenColor(ColorWheel.getNextColor());
63-
Tortoise.move(50);
64-
Tortoise.turn(360.0 / 8);
65-
}
66-
}
6760
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.teachingkidsprogramming.recipes.completed.section04mastery.KataQuestions;
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+
// Can you re factor duplicate code?
12+
//
13+
public class DigiFlower_05
14+
{
15+
public static void main(String[] args)
16+
{
17+
Tortoise.show();
18+
Tortoise.setSpeed(10);
19+
Tortoise.getBackgroundWindow().setBackground(PenColors.Grays.Silver);
20+
Tortoise.setPenWidth(3);
21+
createColorPalette();
22+
Tortoise.setX(150);
23+
Tortoise.setY(150);
24+
drawFlower();
25+
Tortoise.setX(400);
26+
Tortoise.setY(300);
27+
drawFlower();
28+
}
29+
private static void drawFlower()
30+
{
31+
int numberOfPetals = 15;
32+
for (int i = 0; i < numberOfPetals; i++)
33+
{
34+
drawPetal();
35+
Tortoise.turn(360.0 / numberOfPetals);
36+
}
37+
}
38+
private static void drawPetal()
39+
{
40+
int petalShape = 8;
41+
for (int i = 0; i < petalShape; i++)
42+
{
43+
Tortoise.setPenColor(ColorWheel.getNextColor());
44+
Tortoise.move(50);
45+
Tortoise.turn(360.0 / petalShape);
46+
}
47+
}
48+
private static void createColorPalette()
49+
{
50+
Color color1 = PenColors.Reds.Red;
51+
Color color2 = PenColors.Oranges.DarkOrange;
52+
Color color3 = PenColors.Yellows.Gold;
53+
Color color4 = PenColors.Yellows.Yellow;
54+
ColorWheel.addColor(color1);
55+
ColorWheel.addColor(color2);
56+
ColorWheel.addColor(color3);
57+
ColorWheel.addColor(color4);
58+
ColorWheel.addColor(color4);
59+
ColorWheel.addColor(color3);
60+
ColorWheel.addColor(color2);
61+
ColorWheel.addColor(color1);
62+
}
63+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.teachingkidsprogramming.recipes.completed.section04mastery.KataQuestions;
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+
// Possible ANSWER
12+
// Can you easily change the number of petals and/or the petal shape now? Why?
13+
//
14+
public class DigiFlower_06_ANSWER
15+
{
16+
public static void main(String[] args)
17+
{
18+
Tortoise.show();
19+
Tortoise.setSpeed(10);
20+
Tortoise.getBackgroundWindow().setBackground(PenColors.Grays.Silver);
21+
Tortoise.setPenWidth(3);
22+
createColorPalette();
23+
drawFlower(150, 150);
24+
drawFlower(400, 300);
25+
}
26+
private static void drawFlower(int x, int y)
27+
{
28+
Tortoise.setX(x);
29+
Tortoise.setY(y);
30+
int numberOfPetals = 21;
31+
for (int i = 0; i < numberOfPetals; i++)
32+
{
33+
drawPetal();
34+
Tortoise.turn(360.0 / numberOfPetals);
35+
}
36+
}
37+
private static void drawPetal()
38+
{
39+
int petalShape = 6;
40+
for (int i = 0; i < petalShape; i++)
41+
{
42+
Tortoise.setPenColor(ColorWheel.getNextColor());
43+
Tortoise.move(50);
44+
Tortoise.turn(360.0 / petalShape);
45+
}
46+
}
47+
private static void createColorPalette()
48+
{
49+
Color color1 = PenColors.Reds.Red;
50+
Color color2 = PenColors.Oranges.DarkOrange;
51+
Color color3 = PenColors.Yellows.Gold;
52+
Color color4 = PenColors.Yellows.Yellow;
53+
ColorWheel.addColor(color1);
54+
ColorWheel.addColor(color2);
55+
ColorWheel.addColor(color3);
56+
ColorWheel.addColor(color4);
57+
ColorWheel.addColor(color4);
58+
ColorWheel.addColor(color3);
59+
ColorWheel.addColor(color2);
60+
ColorWheel.addColor(color1);
61+
}
62+
}

0 commit comments

Comments
 (0)