Skip to content

Commit 891bf7d

Browse files
committed
updating refactoring Katas for AdLibs and Giza
1 parent 31aee2c commit 891bf7d

File tree

6 files changed

+185
-53
lines changed

6 files changed

+185
-53
lines changed

src/main/java/org/teachingkidsprogramming/recipes/completed/section02methods/KataQuestions/PyramidsOfGiza_ANSWER_v2.java renamed to src/main/java/org/teachingkidsprogramming/recipes/completed/section02methods/KataQuestions/PyramidsOfGiza_ANSWER_04a.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import org.teachingextensions.logo.Tortoise;
44
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
55

6-
public class PyramidsOfGiza_ANSWER_v2
6+
//
7+
// For teacher - reflect on this code vs. the staring code block
8+
// Ask students "Why is human readability for code important?"
9+
// Also "What makes this code more readable than first code sample in this lesson?"
10+
//
11+
public class PyramidsOfGiza_ANSWER_04a
712
{
813
public static void main(String[] args) throws Exception
914
{
@@ -18,18 +23,18 @@ private static void drawPyramids(int numberOfPyramids)
1823
positionNextPyramid(90, 140, -45);
1924
}
2025
}
21-
private static void positionNextPyramid(int angleToTurn, int lengthToMove, int angleToTurnTwo)
22-
{
23-
Tortoise.turn(angleToTurn);
24-
Tortoise.move(lengthToMove);
25-
Tortoise.turn(angleToTurnTwo);
26-
}
2726
private static void drawPyramid()
2827
{
2928
drawPyramidSide(100, 90);
3029
drawPyramidSide(100, 135);
3130
drawPyramidSide(140, 90);
3231
}
32+
private static void positionNextPyramid(int angleToTurn, int lengthToMove, int angleToTurnTwo)
33+
{
34+
Tortoise.turn(angleToTurn);
35+
Tortoise.move(lengthToMove);
36+
Tortoise.turn(angleToTurnTwo);
37+
}
3338
private static void drawPyramidSide(int move, int turn)
3439
{
3540
Tortoise.move(move);

src/main/java/org/teachingkidsprogramming/recipes/completed/section02methods/KataQuestions/PyramidsOfGizaRemoveEvenMoreDuplication_ANSWER_04.java renamed to src/main/java/org/teachingkidsprogramming/recipes/completed/section02methods/KataQuestions/PyramidsOfGiza_TooComplex_ANSWER_04b.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// It is also somewhat academic to illustrate 'too much re-factoring'
1313
// Which results in reduced human readability
1414
//
15-
public class PyramidsOfGizaRemoveEvenMoreDuplication_ANSWER_04
15+
public class PyramidsOfGiza_TooComplex_ANSWER_04b
1616
{
1717
public static void main(String[] args) throws Exception
1818
{

src/main/java/org/teachingkidsprogramming/recipes/completed/section06modelviewcontroller/ExceptionalAdLibsVariation.java

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,61 @@ public class ExceptionalAdLibsVariation
66
{
77
public static void main(String[] args)
88
{
9-
String adverb = MessageBox.askForTextInput("What is the adverb?");
10-
if (adverb.isEmpty())
11-
{
12-
MessageBox.showMessage("L Y don't you want to play? To start you need one adverb.");
13-
adverb = askAdverbAgain();
14-
}
15-
if (adverb.matches("[\\d]*"))
16-
{
17-
MessageBox.showMessage("Numbers are NOT adverbs, try again");
18-
adverb = askAdverbAgain();
19-
}
9+
String adverb = askAdverb();
2010
String currentAdverb = adverb;
21-
String edverb = MessageBox.askForTextInput("What is the -ed verb?");
22-
if (edverb.isEmpty())
23-
{
24-
MessageBox.showMessage("Don't like verbs? You need one now.");
25-
edverb = askEdVerbAgain();
26-
}
27-
if (edverb.matches("[\\d]*"))
28-
{
29-
MessageBox.showMessage("Numbers are != verbs, try again");
30-
edverb = askEdVerbAgain();
31-
}
11+
String edverb = askEdVerb();
3212
String currentEdVerb = edverb;
13+
String bodyPart = askBodyPart();
14+
String currentBodyPart = bodyPart;
15+
String currentStory = "Today ";
16+
currentStory = currentStory + "I woke " + currentAdverb + ". ";
17+
currentStory = currentStory + "Then I " + currentEdVerb + " ";
18+
currentStory = currentStory + "my " + currentBodyPart + ". ";
19+
MessageBox.showMessage(currentStory);
20+
}
21+
private static String askBodyPart()
22+
{
3323
String bodyPart = MessageBox.askForTextInput("What is the body part?");
3424
if (bodyPart.isEmpty())
3525
{
3626
MessageBox.showMessage("No body, no story, pay attention and start over");
37-
bodyPart = askBodyPartAgain();
27+
bodyPart = askBodyPart();
3828
}
3929
if (bodyPart.matches("[\\d]*"))
4030
{
4131
MessageBox.showMessage("Numbers <> body parts, try again");
42-
bodyPart = askBodyPartAgain();
32+
bodyPart = askBodyPart();
4333
}
44-
String currentBodyPart = bodyPart;
45-
String currentStory = "Today ";
46-
currentStory = currentStory + "I woke " + currentAdverb + ". ";
47-
currentStory = currentStory + "Then I " + currentEdVerb + " ";
48-
currentStory = currentStory + "my " + currentBodyPart + ". ";
49-
MessageBox.showMessage(currentStory);
50-
}
51-
52-
private static String askBodyPartAgain()
53-
{
54-
String bodyPart;
55-
bodyPart = MessageBox.askForTextInput("What is the body part?");
5634
return bodyPart;
5735
}
58-
59-
private static String askEdVerbAgain()
36+
private static String askEdVerb()
6037
{
61-
String edverb;
62-
edverb = MessageBox.askForTextInput("What is the -ed verb?");
38+
String edverb = MessageBox.askForTextInput("What is the -ed verb?");
39+
if (edverb.isEmpty())
40+
{
41+
MessageBox.showMessage("Don't like verbs? You need one now.");
42+
edverb = askEdVerb();
43+
}
44+
if (edverb.matches("[\\d]*"))
45+
{
46+
MessageBox.showMessage("Numbers are != verbs, try again");
47+
edverb = askEdVerb();
48+
}
6349
return edverb;
6450
}
65-
66-
private static String askAdverbAgain()
51+
private static String askAdverb()
6752
{
68-
String adverb;
69-
adverb = MessageBox.askForTextInput("What is the adverb?");
53+
String adverb = MessageBox.askForTextInput("What is the adverb?");
54+
if (adverb.isEmpty())
55+
{
56+
MessageBox.showMessage("Y don't you want to play? To start you need one adverb.");
57+
adverb = askAdverb();
58+
}
59+
if (adverb.matches("[\\d]*"))
60+
{
61+
MessageBox.showMessage("Numbers are NOT adverbs, try again");
62+
adverb = askAdverb();
63+
}
7064
return adverb;
7165
}
7266
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section06modelviewcontroller/AdLibsKataQuestion.java renamed to src/main/java/org/teachingkidsprogramming/recipes/completed/section06modelviewcontroller/KataQuestions/AdLibsKataQuestion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.teachingkidsprogramming.recipes.completed.section06modelviewcontroller;
1+
package org.teachingkidsprogramming.recipes.completed.section06modelviewcontroller.KataQuestions;
22

33
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.teachingkidsprogramming.recipes.completed.section06modelviewcontroller.KataQuestions;
2+
3+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
4+
5+
public class ExceptionalAdLibs_ANSWER_1
6+
{
7+
public static void main(String[] args)
8+
{
9+
String adverb = askAdverb();
10+
String currentAdverb = adverb;
11+
String edverb = askEdVerb();
12+
String currentEdVerb = edverb;
13+
String bodyPart = askBodyPart();
14+
String currentBodyPart = bodyPart;
15+
String currentStory = "Today ";
16+
currentStory = currentStory + "I woke " + currentAdverb + ". ";
17+
currentStory = currentStory + "Then I " + currentEdVerb + " ";
18+
currentStory = currentStory + "my " + currentBodyPart + ". ";
19+
MessageBox.showMessage(currentStory);
20+
}
21+
private static String askBodyPart()
22+
{
23+
String bodyPart = MessageBox.askForTextInput("What is the body part?");
24+
if (bodyPart.isEmpty())
25+
{
26+
MessageBox.showMessage("No body, no story, pay attention and start over");
27+
bodyPart = askBodyPart();
28+
}
29+
if (bodyPart.matches("[\\d]*"))
30+
{
31+
MessageBox.showMessage("Numbers <> body parts, try again");
32+
bodyPart = askBodyPart();
33+
}
34+
return bodyPart;
35+
}
36+
private static String askEdVerb()
37+
{
38+
String edverb = MessageBox.askForTextInput("What is the -ed verb?");
39+
if (edverb.isEmpty())
40+
{
41+
MessageBox.showMessage("Don't like verbs? You need one now.");
42+
edverb = askEdVerb();
43+
}
44+
if (edverb.matches("[\\d]*"))
45+
{
46+
MessageBox.showMessage("Numbers are != verbs, try again");
47+
edverb = askEdVerb();
48+
}
49+
return edverb;
50+
}
51+
private static String askAdverb()
52+
{
53+
String adverb = MessageBox.askForTextInput("What is the adverb?");
54+
if (adverb.isEmpty())
55+
{
56+
MessageBox.showMessage("Y don't you want to play? To start you need one adverb.");
57+
adverb = askAdverb();
58+
}
59+
if (adverb.matches("[\\d]*"))
60+
{
61+
MessageBox.showMessage("Numbers are NOT adverbs, try again");
62+
adverb = askAdverb();
63+
}
64+
return adverb;
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.teachingkidsprogramming.recipes.completed.section06modelviewcontroller.KataQuestions;
2+
3+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
4+
5+
public class ExceptionalAdLibs_ANSWER_2
6+
{
7+
public static void main(String[] args)
8+
{
9+
//TODO - use arrays to re-factor duplication
10+
String adverb = askAdverb();
11+
String currentAdverb = adverb;
12+
String edverb = askEdVerb();
13+
String currentEdVerb = edverb;
14+
String bodyPart = askBodyPart();
15+
String currentBodyPart = bodyPart;
16+
String currentStory = "Today ";
17+
currentStory = currentStory + "I woke " + currentAdverb + ". ";
18+
currentStory = currentStory + "Then I " + currentEdVerb + " ";
19+
currentStory = currentStory + "my " + currentBodyPart + ". ";
20+
MessageBox.showMessage(currentStory);
21+
}
22+
private static String askBodyPart()
23+
{
24+
String bodyPart = MessageBox.askForTextInput("What is the body part?");
25+
if (bodyPart.isEmpty())
26+
{
27+
MessageBox.showMessage("No body, no story, pay attention and start over");
28+
bodyPart = askBodyPart();
29+
}
30+
if (bodyPart.matches("[\\d]*"))
31+
{
32+
MessageBox.showMessage("Numbers <> body parts, try again");
33+
bodyPart = askBodyPart();
34+
}
35+
return bodyPart;
36+
}
37+
private static String askEdVerb()
38+
{
39+
String edverb = MessageBox.askForTextInput("What is the -ed verb?");
40+
if (edverb.isEmpty())
41+
{
42+
MessageBox.showMessage("Don't like verbs? You need one now.");
43+
edverb = askEdVerb();
44+
}
45+
if (edverb.matches("[\\d]*"))
46+
{
47+
MessageBox.showMessage("Numbers are != verbs, try again");
48+
edverb = askEdVerb();
49+
}
50+
return edverb;
51+
}
52+
private static String askAdverb()
53+
{
54+
String adverb = MessageBox.askForTextInput("What is the adverb?");
55+
if (adverb.isEmpty())
56+
{
57+
MessageBox.showMessage("Y don't you want to play? To start you need one adverb.");
58+
adverb = askAdverb();
59+
}
60+
if (adverb.matches("[\\d]*"))
61+
{
62+
MessageBox.showMessage("Numbers are NOT adverbs, try again");
63+
adverb = askAdverb();
64+
}
65+
return adverb;
66+
}
67+
}

0 commit comments

Comments
 (0)