Skip to content

Commit 3e59655

Browse files
author
Lynn Langit
committed
added AdLibs Quiz and more w/Llew
1 parent 4412ac9 commit 3e59655

7 files changed

Lines changed: 326 additions & 4 deletions

File tree

11.4 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.teachingkidsprogramming.recipes.quizzes.graders;
2+
3+
4+
public class AdLibsQuizAdapter
5+
{
6+
public static class Pieces
7+
{
8+
public String beginning;
9+
public String middle;
10+
public String end;
11+
}
12+
public String word1;
13+
public String word2;
14+
public String word3;
15+
public String template4;
16+
public void question1(String letter1, String letter3)
17+
{
18+
}
19+
public void question2(String letter1)
20+
{
21+
}
22+
public void question3(String templateText, Object model)
23+
{
24+
}
25+
public void question4(Pieces pieces)
26+
{
27+
}
28+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package org.teachingkidsprogramming.recipes.quizzes.graders;
2+
3+
import java.awt.Font;
4+
import java.awt.Graphics2D;
5+
6+
import javax.swing.JPanel;
7+
8+
import org.teachingextensions.logo.Colors;
9+
import org.teachingextensions.logo.Paintable;
10+
import org.teachingextensions.logo.Tortoise;
11+
import org.teachingextensions.simpleparser.Parser;
12+
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter.Pieces;
13+
14+
public class AdLibsQuizGrader implements Paintable
15+
{
16+
private static class Model
17+
{
18+
public String three;
19+
public Model(String three)
20+
{
21+
this.three = three;
22+
}
23+
}
24+
private boolean[] answers;
25+
public static int TURTLE_SPEED = 9;
26+
private AdLibsQuizAdapter quiz;
27+
private void displayScreen()
28+
{
29+
QuizUtils.prepareScoringScreen(answers, this, TURTLE_SPEED);
30+
}
31+
public void grade(AdLibsQuizAdapter quiz)
32+
{
33+
this.quiz = quiz;
34+
answers = new boolean[]{grade1You(), grade2Won(), grade3The(), grade4Game()};
35+
displayScreen();
36+
}
37+
public void paint(Graphics2D g, JPanel caller)
38+
{
39+
QuizUtils.displayScores(g, 300, answers);
40+
Tortoise.hide();
41+
drawRewardShape(g);
42+
}
43+
public void drawRewardShape(Graphics2D g)
44+
{
45+
drawYou(g);
46+
drawWin(g);
47+
drawThe(g);
48+
drawGame(g);
49+
}
50+
private void drawGame(Graphics2D g)
51+
{
52+
quiz.template4 = "";
53+
Pieces pieces = new Pieces();
54+
quiz.question4(pieces);
55+
pieces.middle = "am";
56+
String word = Parser.parse(quiz.template4, pieces);
57+
drawWord(g, word, 0, 4, true);
58+
}
59+
private void drawThe(Graphics2D g)
60+
{
61+
quiz.word3 = "";
62+
Pieces model = new Pieces();
63+
model.middle = "H";
64+
quiz.question3("T{middle}E", model);
65+
drawWord(g, quiz.word3, 3, 2, false);
66+
}
67+
private void drawWin(Graphics2D g)
68+
{
69+
quiz.word2 = "WO";
70+
quiz.question2("n");
71+
drawWord(g, quiz.word2, 1, 0, false);
72+
}
73+
private void drawWord(Graphics2D g, String word, int x, int y, boolean horizontal)
74+
{
75+
char[] letters = word.toUpperCase().toCharArray();
76+
int dx = horizontal ? 1 : 0;
77+
int dy = horizontal ? 0 : 1;
78+
for (int i = 0; i < letters.length; i++)
79+
{
80+
char c = letters[i];
81+
drawLetter(getPosition(x + dx * i), getPosition(y + dy * i), c, g);
82+
}
83+
}
84+
private int getPosition(int i)
85+
{
86+
return 100 + i * 53;
87+
}
88+
private void drawYou(Graphics2D g)
89+
{
90+
quiz.word1 = "NOT";
91+
quiz.question1("y", "u");
92+
drawWord(g, quiz.word1, 0, 1, true);
93+
}
94+
private void drawLetter(int x, int y, char c, Graphics2D g)
95+
{
96+
g.setColor(Colors.Browns.BurlyWood);
97+
g.drawRect(x, y, 50, 50);
98+
g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 36));
99+
int charWidth = g.getFontMetrics().charWidth(c);
100+
int charHeight = g.getFontMetrics().getAscent();
101+
int textY = y + (40 - charHeight) / 2 + charHeight;
102+
int textX = x + (50 - charWidth) / 2;
103+
g.drawString("" + c, textX, textY);
104+
}
105+
private boolean grade1You()
106+
{
107+
quiz.word1 = "fake";
108+
quiz.question1("f", "o");
109+
return "foo".equals(quiz.word1);
110+
}
111+
private boolean grade2Won()
112+
{
113+
quiz.word2 = "passe";
114+
quiz.question2("d");
115+
return "passed".equals(quiz.word2);
116+
}
117+
private boolean grade3The()
118+
{
119+
quiz.word3 = "fake";
120+
quiz.question3("12{three}4", new Model("3"));
121+
return "1234".equals(quiz.word3);
122+
}
123+
private boolean grade4Game()
124+
{
125+
quiz.template4 = "fake";
126+
quiz.question4(new Pieces());
127+
return "g{middle}e".equals(quiz.template4);
128+
}
129+
}

TeachingKidsProgramming/src/org/teachingkidsprogramming/section01forloops/SimpleSquare.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.teachingkidsprogramming.section01forloops;
22

3+
34
public class SimpleSquare
45
{
56
public static void main(String[] args) throws Exception

TeachingKidsProgramming/src/org/teachingkidsprogramming/section04mastery/DeepDive04Mastery.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ public class DeepDive04Mastery
1919
// Step 5: Advance to the next method
2020
// Do not change anything except the blank (___)
2121
//
22-
// concepts to cover: types, scope
23-
// no inheritance,no new, int->double, int->string
24-
// primitive types
25-
// possible auto-boxing
2622
@Test
2723
public void theseNumbersCount() throws Exception
2824
{
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package org.teachingkidsprogramming.section05recursion;
2+
3+
import java.awt.Color;
4+
import java.awt.Cursor;
5+
import java.util.HashMap;
6+
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
import org.teachingextensions.logo.Colors;
10+
import org.teachingextensions.logo.Tortoise;
11+
12+
//
13+
public class DeepDive05Recursion
14+
{
15+
// How to do deep dive:
16+
// Step 1: Select the method name (doesABear on line 20) Press the Run Button
17+
// PC: Ctrl+F11
18+
// Mac: Command+fn+F11
19+
// Step 2: Read the name of the method that failed
20+
// Step 3: Fill in the blank (___) to make it pass
21+
// Step 4: Consider at least one thing you just learned
22+
// Step 5: Advance to the next method
23+
// Do not change anything except the blank (___)
24+
//
25+
// collections (hashmaps and more...)
26+
//Hashmap = C# Dictionary
27+
// HashMap<K,V>
28+
//Array = C# Array
29+
// Integer [ ] = {1,2,3};
30+
// Integer [ ] = new Integer [3];
31+
// List = C# ArrayList
32+
// List = new ArrayLIst( );
33+
// concepts to cover: recursion
34+
// possible recursive ideas from lisp/clojure
35+
// (defn is-even? [n] (if (= n 0) (___ (is-even? (dec n)))))
36+
// (defn recursive-reverse [coll] __)
37+
@Test
38+
public void gettingStarted() throws Exception
39+
{
40+
int number = 2;
41+
Assert.assertEquals(number, ____);
42+
}
43+
@Test
44+
public void changeThePointer() throws Exception
45+
{
46+
//Set the cursor on the background window to a hand
47+
Tortoise.getBackgroundWindow().___();
48+
Assert.assertEquals(getCursor(), Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
49+
}
50+
@Test
51+
public void getTheWindow() throws Exception
52+
{
53+
//Get the correct background window in order to set the cursor
54+
Tortoise.___().setCursor(Cursor.CROSSHAIR_CURSOR);
55+
Assert.assertEquals(getCursor(), Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
56+
}
57+
@Test
58+
public void setPositionUsingHashKey() throws Exception
59+
{
60+
//set the color Dark Green into the right spot using the key
61+
HashMap<Integer, Color> colors = new HashMap<Integer, Color>();
62+
colors.put(10, Colors.Greens.Lime);
63+
colors.put(____, Colors.Greens.DarkGreen);
64+
Assert.assertEquals(Colors.Greens.DarkGreen, colors.get(20));
65+
}
66+
@Test
67+
public void getValueUsingHashKey() throws Exception
68+
{
69+
//get the key from the right spot using the color
70+
HashMap<Integer, Color> colors = new HashMap<Integer, Color>();
71+
colors.put(20, Colors.Greens.DarkGreen);
72+
colors.put(30, Colors.Greens.Green);
73+
Assert.assertEquals(Colors.Greens.Green, colors.get(___));
74+
}
75+
@Test
76+
public void getColorUsingHashKey() throws Exception
77+
{
78+
//get the color from the right spot using the key
79+
HashMap<Integer, Color> colors = new HashMap<Integer, Color>();
80+
colors.put(20, Colors.Greens.DarkGreen);
81+
colors.put(30, Colors.Greens.Green);
82+
Assert.assertEquals(_______, colors.get(30));
83+
}
84+
@Test
85+
public void getThirdArrayItem() throws Exception
86+
{
87+
//get the third item from the right spot using the key
88+
int[] numbers = {1, 5, 10, 25};
89+
Assert.assertEquals(10, numbers[____]);
90+
}
91+
@Test
92+
public void whatDoesItStartWith() throws Exception
93+
{
94+
//put 25 at the third position
95+
int[] numbers = {1, 5, 10, ____};
96+
Assert.assertEquals(25, numbers[3]);
97+
}
98+
@Test
99+
public void whatIsFirst() throws Exception
100+
{
101+
//get the number at the first position
102+
int[] numbers = {1, 5, 10, 25};
103+
Assert.assertEquals(____, numbers[1]);
104+
}
105+
@Test
106+
public void whatIsFirstNow() throws Exception
107+
{
108+
//change the number at the listed position
109+
int[] numbers = {1, 5, 10, 25};
110+
numbers[0] = ____;
111+
Assert.assertEquals(53, numbers[0]);
112+
}
113+
/**
114+
* Ignore the following, It's needed to run the homework
115+
*
116+
*
117+
*
118+
*
119+
*
120+
*
121+
*
122+
*
123+
*
124+
*
125+
*/
126+
public boolean _____ = false;
127+
public boolean ______ = true;
128+
public String ___ = "You need to fill in the blank ___";
129+
public int ____ = 0;
130+
public Color _______;
131+
public String ___()
132+
{
133+
return ___;
134+
}
135+
private Cursor getCursor()
136+
{
137+
Cursor cursor = Tortoise.getBackgroundWindow().getCursor();
138+
return cursor;
139+
}
140+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.teachingkidsprogramming.section06modelviewcontroller;
2+
3+
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizAdapter;
4+
import org.teachingkidsprogramming.recipes.quizzes.graders.AdLibsQuizGrader;
5+
6+
public class AdLibsQuiz extends AdLibsQuizAdapter
7+
{
8+
public void question1(String letter1, String letter3)
9+
{
10+
//set current value of word1 to be letter1 + 'o' + letter3
11+
}
12+
public void question2(String letter1)
13+
{
14+
//add the letter1 to the end of word2
15+
}
16+
public void question3(String templateText, Object model)
17+
{
18+
//use the parser to combine the template and the model as word3
19+
}
20+
public void question4(Pieces pieces)
21+
{
22+
//set template4 to the template which does'g' + pieces.middle + 'e'
23+
}
24+
public static void main(String[] args)
25+
{
26+
new AdLibsQuizGrader().grade(new AdLibsQuiz());
27+
}
28+
}

0 commit comments

Comments
 (0)