Skip to content

Commit 3c65e84

Browse files
committed
Finished DD7 w/Jim
1 parent 5ec22a3 commit 3c65e84

3 files changed

Lines changed: 85 additions & 16 deletions

File tree

src/org/teachingextensions/logo/Pizza.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
public class Pizza
66
{
77
private ArrayList<Topping> toppings = new ArrayList<Topping>();
8+
private boolean cooked;
9+
private int slices = 2;
810
public void addTopping(Topping topping)
911
{
1012
this.toppings.add(topping);
@@ -17,4 +19,28 @@ public boolean hasTopping(Topping topping)
1719
}
1820
return false;
1921
}
22+
public void cook()
23+
{
24+
this.cooked = true;
25+
}
26+
public boolean wasCooked()
27+
{
28+
return this.cooked;
29+
}
30+
public void ____()
31+
{
32+
}
33+
public boolean takeSlice()
34+
{
35+
if (0 < this.slices)
36+
{
37+
this.slices--;
38+
return true;
39+
}
40+
return false;
41+
}
42+
public void superSizeIt()
43+
{
44+
this.slices = 8;
45+
}
2046
}

src/org/teachingextensions/logo/Tortoise.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ public static TurtlePanel ___()
255255
private Topping topping;
256256
public boolean eatPizza(Pizza pizza)
257257
{
258-
return pizza.hasTopping(topping);
258+
if (!pizza.takeSlice()) { return false; }
259+
if (this.topping == null) { return true; }
260+
if (this.topping != Topping.Cheese) { return pizza.hasTopping(topping); }
261+
return pizza.wasCooked() && pizza.hasTopping(topping);
259262
}
260263
public void likesTopping(Topping topping)
261264
{

src/org/teachingkidsprogramming/section07events/DeepDive07Events.java

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import org.teachingextensions.logo.Tortoise;
1010
import org.teachingextensions.logo.Turtle;
1111
import org.teachingextensions.logo.Turtle.Animals;
12-
//This deepdive is in progress!
1312

14-
//@Ignore
1513
public class DeepDive07Events
1614
{
1715
// How to do deep dive:
18-
// Step 1: Select the method name (xxx on line xx) Press the Run Button
16+
// Step 1: Select the method name (twoTortoises on line 30) Press the Run Button
1917
// PC: Ctrl+F11
2018
// Mac: Command+fn+F11
2119
// Step 2: Read the name of the method that failed
@@ -24,17 +22,6 @@ public class DeepDive07Events
2422
// Step 5: Advance to the next method
2523
// Do not change anything except the blank (___)
2624
//
27-
// concepts:
28-
// 'this' - instance(s) - multiple Tortoises
29-
// exploring Object methods other than Tortoise---Circle (TKP)...methods
30-
// events / multiple event listeners - right click - move events to new section?
31-
@Test
32-
public void stringsCanBeArrays() throws Exception
33-
{
34-
String[] words = {"happy ", ___};
35-
String result = words[0] + words[1];
36-
Assert.assertEquals("happy baby", result);
37-
}
3825
@Test
3926
public void twoTortoises() throws Exception
4027
{
@@ -98,7 +85,50 @@ public void feedTheNinjaTwo() throws Exception
9885
Pizza pizza = new Pizza();
9986
pizza.addTopping(Topping.Anchovy);
10087
boolean likedIt = karai.eatPizza(pizza);
101-
Assert.assertTrue("Karai starves! Wrong pizza!", _____);
88+
Assert.assertTrue("Karai turns greener! Wrong pizza!", _____);
89+
}
90+
@Test
91+
public void checkOutThePizza() throws Exception
92+
{
93+
Tortoise cecil = new Tortoise();
94+
cecil.likesTopping(Topping.Cheese);
95+
Pizza pizza = new Pizza();
96+
pizza.addTopping(Topping.Cheese);
97+
pizza.____();
98+
boolean likedIt = cecil.eatPizza(pizza);
99+
Assert.assertTrue("Cecil sends it back! Wrong pizza!", likedIt);
100+
}
101+
@Test
102+
public void feedAllTheNinjas() throws Exception
103+
{
104+
Tortoise[] tortoises = throwPizzaParty();
105+
Pizza pizza = new Pizza();
106+
pizza.____();
107+
for (Tortoise tortoise : tortoises)
108+
{
109+
gotASlice = tortoise.eatPizza(pizza);
110+
if (!gotASlice)
111+
{
112+
break;
113+
}
114+
}
115+
Assert.assertTrue("The ninja flips out - not enough pizza!", gotASlice);
116+
}
117+
@Test
118+
public void feedAllTheNinjasAgain() throws Exception
119+
{
120+
Tortoise[] tortoises = throwPizzaParty();
121+
Pizza pizza = new Pizza();
122+
pizza.superSizeIt();
123+
for (Tortoise tortoise : tortoises)
124+
{
125+
_____ = tortoise.eatPizza(pizza);
126+
if (!this.gotASlice)
127+
{
128+
break;
129+
}
130+
}
131+
Assert.assertTrue("The ninja flips out - not enough pizza!", this.gotASlice);
102132
}
103133
/**
104134
* Ignore the following, It's needed to run the homework
@@ -113,6 +143,16 @@ public void feedTheNinjaTwo() throws Exception
113143
*
114144
*
115145
*/
146+
private Tortoise[] throwPizzaParty()
147+
{
148+
Tortoise karai = new Tortoise();
149+
Tortoise cecil = new Tortoise();
150+
Tortoise michealangelo = new Tortoise();
151+
Tortoise fred = new Tortoise();
152+
Tortoise[] tortoises = {karai, cecil, michealangelo, fred};
153+
return tortoises;
154+
}
155+
private boolean gotASlice;
116156
public boolean _____ = false;
117157
public boolean ______ = true;
118158
public String ___ = "You need to fill in the blank ___";

0 commit comments

Comments
 (0)