Skip to content

Commit 4bc3dc9

Browse files
committed
working on C7,8,9 w/@mballin
1 parent 4a8d30f commit 4bc3dc9

9 files changed

Lines changed: 229 additions & 390 deletions

File tree

src/main/java/org/teachingextensions/WindowUtils/MultiTurtleWindow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class MultiTurtleWindow extends TurtlePanel
2626
private Animals animal = Animals.Turtle;
2727
public MultiTurtleWindow()
2828
{
29-
super("So Many Turtles");
29+
super("Turtles, Turtles, Turtles!");
3030
this.image = loadAnimal();
3131
}
3232
/**

src/main/java/org/teachingextensions/logo/utils/MazeUtils/Maze.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private void generate()
115115
int y = 1 + StdRandom.uniform(N-1);
116116
north[x][y] = south[x][y+1] = false;
117117
}
118-
118+
119119
// add some random walls
120120
for (int i = 0; i < 10; i++) {
121121
int x = N/2 + StdRandom.uniform(N/2);

src/main/java/org/teachingkidsprogramming/recipes/completed/section00demos/RecipeForTestingVirtualProctor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void main(String[] args) throws Exception
2222
Tortoise.move(75);
2323
Tortoise.turn(360 / sides);
2424
Sound s = new Sound();
25-
s.setSound(Sound.TKPSound.FargoYah);
25+
s.setSound(Sound.TKPSound.LLCoolJYaKnow);
2626
s.playSound();
2727
}
2828
VirtualProctor.setClassName("TKPHouseAtHome");
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.teachingkidsprogramming.recipes.completed.section07objects;
2+
3+
import org.teachingextensions.WindowUtils.MultiTurtleWindow;
4+
import org.teachingextensions.logo.Turtle;
5+
6+
public class SuperSoundingTurtles
7+
{
8+
public MultiTurtleWindow mtw = new MultiTurtleWindow();
9+
public SuperSoundingTurtles()
10+
{
11+
showSomeTurtles();
12+
}
13+
public static void main(String[] args)
14+
{
15+
new SuperSoundingTurtles();
16+
}
17+
private void showSomeTurtles()
18+
{
19+
makeSpeedyTurtle();
20+
makeSlowTurtle();
21+
makeCrazyTurtle();
22+
}
23+
private void makeSpeedyTurtle()
24+
{
25+
Turtle speedyTurtle = new Turtle();
26+
mtw.addAndShowTurtle(speedyTurtle);
27+
speedyTurtle.setSpeed(10);
28+
speedyTurtle.drawTriangle(100);
29+
//
30+
//***Need to add the ability to play sounds to MultiTurtleWindow (sync)****//
31+
//***Add 'funny' sounds to each drawing section of this recipe*************//
32+
//Sound s = new Sound();
33+
//s.setSound(Sound.TKPSound.LLCoolJYaKnow);
34+
//s.playSound();
35+
}
36+
private void makeSlowTurtle()
37+
{
38+
Turtle slowTurtle = new Turtle();
39+
mtw.addAndShowTurtle(slowTurtle);
40+
slowTurtle.drawTriangle(-50);
41+
//Add sound
42+
}
43+
private void makeCrazyTurtle()
44+
{
45+
Turtle crazyTurtle = new Turtle();
46+
mtw.addTurtle(crazyTurtle);
47+
crazyTurtle.drawLightning(55);
48+
//Add Sound
49+
}
50+
}
Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
11
package org.teachingkidsprogramming.recipes.completed.section08events;
22

3-
import java.awt.Color;
43
import java.awt.event.ActionEvent;
54
import java.awt.event.ActionListener;
65

76
import javax.swing.ImageIcon;
87
import javax.swing.JButton;
98

109
import org.teachingextensions.logo.Tortoise;
11-
import org.teachingextensions.logo.utils.ColorUtils.ColorWheel;
1210
import org.teachingextensions.logo.utils.ColorUtils.PenColors;
13-
import org.teachingextensions.logo.utils.EventUtils.MouseRightClickListener;
14-
import org.teachingextensions.logo.utils.LineAndShapeUtils.Circle;
1511

16-
@SuppressWarnings("unused")
17-
//***********************In Progress***************************//
18-
public class TortoiseMaze implements MouseRightClickListener
12+
//***********************ANSWER: In Progress***************************//
13+
// Need to write English comments and copy to STUDENT section //
14+
//
15+
public class TortoiseMaze
1916
{
2017
public static void main(String[] args)
2118
{
2219
new TortoiseMaze();
2320
}
2421
public TortoiseMaze()
2522
{
26-
Tortoise.getBackgroundWindow().addMouseRightClickListener(this);
2723
Tortoise.setSpeed(10);
2824
Tortoise.setPenColor(PenColors.Greens.Green);
2925
Tortoise.setPenWidth(4);
30-
clearTheScreen();
31-
prepareColorPalette();
32-
ImageIcon arrowIconL = new ImageIcon(
26+
ImageIcon leftArrow = new ImageIcon(
3327
"../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-left.png");
34-
JButton leftButton = new JButton(arrowIconL);
28+
JButton leftButton = new JButton(leftArrow);
3529
Tortoise.getBackgroundWindow().addButton(leftButton);
36-
ImageIcon arrowIconU = new ImageIcon(
30+
ImageIcon upArrow = new ImageIcon(
3731
"../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-up.png");
38-
JButton upButton = new JButton(arrowIconU);
32+
JButton upButton = new JButton(upArrow);
3933
Tortoise.getBackgroundWindow().addButton(upButton);
40-
ImageIcon arrowIconR = new ImageIcon(
34+
ImageIcon rightArrow = new ImageIcon(
4135
"../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-right.png");
42-
JButton rightButton = new JButton(arrowIconR);
36+
JButton rightButton = new JButton(rightArrow);
4337
Tortoise.getBackgroundWindow().addButton(rightButton);
4438
rightButton.addActionListener(new ActionListener()
4539
{
@@ -67,36 +61,4 @@ public void actionPerformed(ActionEvent e)
6761
});
6862
Tortoise.setVisible(true);
6963
}
70-
private static void prepareColorPalette()
71-
{
72-
ColorWheel.addColor(PenColors.Reds.Red);
73-
ColorWheel.addColor(PenColors.Greens.Green);
74-
ColorWheel.addColor(PenColors.Blues.Blue);
75-
ColorWheel.addColor(PenColors.Purples.Purple);
76-
ColorWheel.addColor(PenColors.Pinks.Pink);
77-
ColorWheel.addColor(PenColors.Greens.Teal);
78-
}
79-
private void addDot(int x, int y)
80-
{
81-
addCircle(x, y);
82-
Tortoise.moveTo(x, y);
83-
}
84-
private void addCircle(int x, int y)
85-
{
86-
int radius = 7;
87-
Color color = ColorWheel.getNextColor();
88-
Circle circle = new Circle(radius, color);
89-
circle.setTransparency(60);
90-
circle.setCenter(x, y);
91-
circle.addTo(Tortoise.getBackgroundWindow());
92-
}
93-
private static void clearTheScreen()
94-
{
95-
Tortoise.clear();
96-
}
97-
@Override
98-
public void onRightMouseClick(int x, int y)
99-
{
100-
clearTheScreen();
101-
}
10264
}
Lines changed: 62 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,31 @@
11
package org.teachingkidsprogramming.recipes.completed.section09final;
22

3-
import java.awt.Cursor;
4-
53
import org.junit.Assert;
64
import org.junit.Test;
7-
import org.teachingextensions.logo.Tortoise;
5+
import org.teachingextensions.approvals.lite.util.FormattedException;
86

9-
//This deepdive is in progress!
7+
//**************ANSWER: This deepdive is in progress!*****************//
8+
//
109
@SuppressWarnings("unused")
1110
public class DeepDive09
1211
{
1312
@Test
14-
public void stringsCanBeArrays() throws Exception
15-
{
16-
String[] words = {"happy ", "baby"};
17-
String result = words[0] + words[1];
18-
Assert.assertEquals("happy baby", result);
19-
}
20-
@Test
21-
public void stringsCanBePartOfStringBuilder() throws Exception
22-
{
23-
StringBuilder sb = new StringBuilder();
24-
sb.append("happy");
25-
sb.append(" baby");
26-
String result = sb.toString();
27-
Assert.assertEquals("happy baby", result);
28-
}
29-
@Test
30-
public void stringsCanBePartOfStringBuilderAgain() throws Exception
31-
{
32-
StringBuilder sb = new StringBuilder();
33-
sb.append("very happy");
34-
sb.append(" lady");
35-
String result = sb.toString();
36-
Assert.assertEquals("very happy lady", result);
37-
}
38-
@Test
39-
public void stringsCanBeReversedInStringBuilder() throws Exception
40-
{
41-
StringBuilder sb = new StringBuilder("very happy lady");
42-
sb.reverse();
43-
String result = sb.toString();
44-
Assert.assertEquals(result, result);
45-
}
46-
@Test
47-
public void numbersCanBeStrings() throws Exception
48-
{
49-
StringBuilder sb = new StringBuilder();
50-
for (int i = 97; i < 99; i++)
51-
{
52-
sb.append(convertArray(i));
53-
}
54-
String result = sb.toString();
55-
Assert.assertEquals(result, result);
56-
}
57-
@Test
58-
public void numbersCanBeStringsAgain() throws Exception
59-
{
60-
StringBuilder sb = new StringBuilder();
61-
for (int i = 99; i > 96; i--)
62-
{
63-
sb.append(convertArray(i));
64-
}
65-
String result = sb.toString();
66-
Assert.assertEquals(" 99 98 97", result);
67-
}
68-
@Test
69-
public void theLineEndsWhenItEnds() throws Exception
70-
{
71-
StringBuilder sb = new StringBuilder("one end ");
72-
sb.append("\n");
73-
sb.append(" another end");
74-
String result = sb.toString();
75-
Assert.assertEquals(result, result);
76-
}
77-
@Test
78-
public void theLineEndsReally() throws Exception
13+
public void exceptionsShouldProvideInformation() throws Exception
7914
{
80-
StringBuilder sb = new StringBuilder("one end ");
81-
sb.append("\n");
82-
sb.append(" another end ");
83-
sb.append("\n");
84-
String result = sb.toString();
85-
Assert.assertEquals("one end \n another end \n", result);
15+
Chain c = createChain();
16+
int answer = c.get("a").get("b").get("c").get("d").get("e").value; /* Fix This Line */
17+
Assert.assertEquals(2048, answer);
8618
}
8719
@Test
88-
public void chainThoseMethods() throws Exception
20+
public void exceptionsShouldExplainPreconditions() throws Exception
8921
{
90-
StringBuilder sb = new StringBuilder("method");
91-
String result = sb.reverse().toString();
92-
Assert.assertEquals(result, result);
22+
Game game = new Game();
23+
/* Add needed line here */
24+
int fun = game.play();
25+
Assert.assertEquals(11, fun);
9326
}
9427
/**
95-
* Ignore the following, It's needed to run the deep dive
28+
* Ignore the following, It's needed to run the homework
9629
*
9730
*
9831
*
@@ -104,22 +37,59 @@ public void chainThoseMethods() throws Exception
10437
*
10538
*
10639
*/
107-
public boolean _____ = false;
108-
public boolean ______ = true;
109-
public Character _______;
110-
public String ___ = "You need to fill in the blank ___";
111-
public int ____ = 0;
112-
public String ___()
40+
private int call(int a, int b, int c)
11341
{
114-
return ___;
42+
if (((a + c) / 2) == b) { throw new FormattedException("%s is not a valid input for (%s, %s, %s)", b, a, b,
43+
c); }
44+
return a + b + c;
11545
}
116-
private Cursor getCursor()
46+
private static class Game
11747
{
118-
Cursor cursor = Tortoise.getBackgroundWindow().getCursor();
119-
return cursor;
48+
boolean on = false;
49+
public void turnOn()
50+
{
51+
on = true;
52+
}
53+
public int play()
54+
{
55+
if (!on) { throw new FormattedException(
56+
"Before you can play a game you need to turn it on.\n game.turnOn()"); }
57+
return 11;
58+
}
12059
}
121-
public static String convertArray(int i)
60+
private static class Chain
12261
{
123-
return " " + i;
62+
private String label;
63+
private Chain chain;
64+
public int value;
65+
public Chain(String label, Chain chain)
66+
{
67+
this.label = label;
68+
this.chain = chain;
69+
}
70+
public Chain(int value)
71+
{
72+
this.value = value;
73+
}
74+
public Chain get(String string)
75+
{
76+
if (!label.equals(
77+
string)) { throw new FormattedException("There is no value for '%s', please use '%s'", string, label); }
78+
return chain;
79+
}
80+
}
81+
private Chain createChain()
82+
{
83+
return new Chain("a", new Chain("b", new Chain("surprise", new Chain("d", new Chain("e", new Chain(2048))))));
84+
}
85+
private static class _____ extends Exception
86+
{
87+
private static final long serialVersionUID = 7013264013388843231L;
88+
public _____(String message, Exception originalException)
89+
{
90+
super(message, originalException);
91+
}
12492
}
93+
public String ___ = "You need to fill in the blank ___";
94+
public Integer ____ = -99;
12595
}

0 commit comments

Comments
 (0)