Skip to content

Commit d083556

Browse files
committed
wrote more Katas w/ @mballin
ReverseHiLow, PyramidsOfGiza and Snowflake possible answers
1 parent 7c2bcec commit d083556

File tree

5 files changed

+157
-2
lines changed

5 files changed

+157
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.teachingkidsprogramming.recipes.completed.section02methods.KataQuestions;
2+
3+
import org.teachingextensions.logo.Tortoise;
4+
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
5+
6+
public class PyramidsOfGiza_ANSWER_v2
7+
{
8+
public static void main(String[] args) throws Exception
9+
{
10+
setUpPyramidLand();
11+
drawPyramids(3);
12+
}
13+
private static void drawPyramids(int numberOfPyramids)
14+
{
15+
for (int i = 0; i < numberOfPyramids; i++)
16+
{
17+
drawPyramid();
18+
positionNextPyramid(90, 140, -45);
19+
}
20+
}
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+
}
27+
private static void drawPyramid()
28+
{
29+
drawPyramidSide(100, 90);
30+
drawPyramidSide(100, 135);
31+
drawPyramidSide(140, 90);
32+
}
33+
private static void drawPyramidSide(int move, int turn)
34+
{
35+
Tortoise.move(move);
36+
Tortoise.turn(turn);
37+
}
38+
private static void setUpPyramidLand()
39+
{
40+
Tortoise.show();
41+
Tortoise.setSpeed(10);
42+
Tortoise.getBackgroundWindow().setBackground(PenColors.Blues.AliceBlue);
43+
Tortoise.setPenColor(PenColors.Yellows.DarkGoldenrod);
44+
Tortoise.setPenWidth(2);
45+
Tortoise.hide();
46+
Tortoise.setX(500);
47+
Tortoise.turn(-90);
48+
Tortoise.move(423);
49+
Tortoise.turn(135);
50+
}
51+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.teachingkidsprogramming.recipes.completed.section03ifs.KataQuestions;
2+
3+
import org.teachingextensions.logo.utils.EventUtils.MessageBox;
4+
5+
//Your user knows the answer, the computer gets 8 guesses to determine the answer
6+
//You tell the computer whether its guess is too high or too low
7+
//Write each of the English line comments (use at least 8 line comments)
8+
//Number each comment line at the end
9+
//Verify - step one - Translate EACH comment line into code
10+
//Verify - step two - Run your code after each line
11+
public class ReverseHiLow_Answer
12+
{
13+
public static void main(String[] args)
14+
{
15+
MessageBox
16+
.showMessage("Hello, actual human! Think of a number between 1 and 100, and I will attempt to guess it.");
17+
MessageBox.showMessage("Click OK when you have one in mind.");
18+
int attemptNumber = 1;
19+
int currentGuess = 50;
20+
int highestPossible = 100;
21+
int lowestPossible = 1;
22+
while (attemptNumber < 8)
23+
{
24+
MessageBox.showMessage("Beginning attempt number " + attemptNumber);
25+
String feedback = MessageBox.askForTextInput("Is " + currentGuess
26+
+ " the correct number? Write 'yes' if it is, if not write 'too high' or 'too low'.");
27+
if (feedback.equals("yes"))
28+
{
29+
MessageBox.showMessage("Got it on attempt number " + attemptNumber + "! Darn, I'm good. See ya!");
30+
System.exit(0);
31+
}
32+
else
33+
{
34+
if (feedback.equalsIgnoreCase("too high"))
35+
{
36+
highestPossible = currentGuess;
37+
currentGuess = currentGuess - ((currentGuess - lowestPossible) / 2);
38+
}
39+
else if (feedback.equalsIgnoreCase("too low"))
40+
{
41+
lowestPossible = currentGuess;
42+
currentGuess = currentGuess + ((highestPossible - currentGuess) / 2);
43+
}
44+
attemptNumber++;
45+
}
46+
}
47+
// Variable: currentGuess
48+
// Computer guesses currentGuess, asks if too high or too low
49+
// User inputs
50+
// If right, computer congratulates itself and ends
51+
// If wrong, computer takes feedback and adjusts currentGuess accordingly
52+
}
53+
}

src/main/java/org/teachingkidsprogramming/section05recursion/KataQuestions/CompleteSnowflake.java renamed to src/main/java/org/teachingkidsprogramming/recipes/completed/section05recursion/KataQuestions/CompleteSnowflake.java

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

33
//------------Snowflake Kata---------------//
44
// Use the Tortoise to draw a snowflake using triangles

src/main/java/org/teachingkidsprogramming/section05recursion/KataQuestions/CompleteSnowflakeAnswer.java renamed to src/main/java/org/teachingkidsprogramming/recipes/completed/section05recursion/KataQuestions/CompleteSnowflakeAnswer.java

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

33
import org.teachingextensions.logo.Tortoise;
44
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.teachingkidsprogramming.recipes.completed.section05recursion.KataQuestions;
2+
3+
import org.teachingextensions.logo.Tortoise;
4+
5+
public class CompleteSnowflakeAnswer2
6+
{
7+
//TODO: write comments and then code here
8+
public static void main(String[] args)
9+
{
10+
setUpTortoise();
11+
//have fun with the level
12+
int currentLevel = 9;
13+
drawTriangle(currentLevel);
14+
}
15+
private static void drawTriangle(int currentLevel)
16+
{
17+
drawTriangleCorner(currentLevel);
18+
if (currentLevel > 1)
19+
{
20+
Tortoise.turn(180);
21+
drawTriangle(currentLevel - 1);
22+
Tortoise.turn(180);
23+
}
24+
drawTriangleCorner(currentLevel);
25+
if (currentLevel > 1)
26+
{
27+
Tortoise.turn(180);
28+
drawTriangle(currentLevel - 1);
29+
Tortoise.turn(180);
30+
}
31+
drawTriangleCorner(currentLevel);
32+
if (currentLevel > 1)
33+
{
34+
Tortoise.turn(180);
35+
drawTriangle(currentLevel - 1);
36+
Tortoise.turn(180);
37+
}
38+
}
39+
private static void drawTriangleCorner(int currentLevel)
40+
{
41+
Tortoise.move(10 * currentLevel);
42+
Tortoise.turn(120);
43+
Tortoise.move(10 * currentLevel);
44+
}
45+
private static void setUpTortoise()
46+
{
47+
Tortoise.show();
48+
Tortoise.setSpeed(10);
49+
Tortoise.turn(-90);
50+
}
51+
}

0 commit comments

Comments
 (0)