Skip to content

Commit c3e3134

Browse files
committed
Added Pizza and Topping! w/Jim
1 parent 6e10a34 commit c3e3134

4 files changed

Lines changed: 53 additions & 5 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.teachingextensions.logo;
2+
3+
import java.util.ArrayList;
4+
5+
public class Pizza
6+
{
7+
private ArrayList<Topping> toppings = new ArrayList<Topping>();
8+
public void addTopping(Topping topping)
9+
{
10+
this.toppings.add(topping);
11+
}
12+
public boolean hasTopping(Topping topping)
13+
{
14+
for (Topping toppingToday : toppings)
15+
{
16+
if (toppingToday == topping) { return true; }
17+
}
18+
return false;
19+
}
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.teachingextensions.logo;
2+
3+
public enum Topping {
4+
NoTopping, Pepperoni, Anchovy, Cheese, Spam, Broccoli
5+
}

src/org/teachingextensions/logo/Tortoise.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,13 @@ public static TurtlePanel ___()
252252
{
253253
return new TurtlePanel();
254254
}
255+
private Topping topping;
256+
public boolean eatPizza(Pizza pizza)
257+
{
258+
return pizza.hasTopping(topping);
259+
}
260+
public void likesTopping(Topping toppping)
261+
{
262+
this.topping = topping;
263+
}
255264
}

src/org/teachingkidsprogramming/section07events/DeepDive07Events.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import org.junit.Assert;
66
import org.junit.Test;
7+
import org.teachingextensions.logo.Pizza;
8+
import org.teachingextensions.logo.Topping;
79
import org.teachingextensions.logo.Tortoise;
810
import org.teachingextensions.logo.Turtle;
911
import org.teachingextensions.logo.Turtle.Animals;
@@ -78,6 +80,17 @@ public void explodingTurtle() throws Exception
7880
this.donatello.setAnimal(Animals.ExplodedTurtle);
7981
Assert.assertTrue("The ninja is still alive!", ninja.isDead());
8082
}
83+
//fix comparitor
84+
@Test
85+
public void feedTheNinja() throws Exception
86+
{
87+
Tortoise michealangelo = new Tortoise();
88+
michealangelo.likesTopping(Topping.Pepperoni);
89+
Pizza pizza = new Pizza();
90+
pizza.addTopping(_________);
91+
boolean likedIt = michealangelo.eatPizza(pizza);
92+
Assert.assertTrue("Michealangelo barfs! Wrong pizza!", likedIt);
93+
}
8194
/**
8295
* Ignore the following, It's needed to run the homework
8396
*
@@ -91,12 +104,13 @@ public void explodingTurtle() throws Exception
91104
*
92105
*
93106
*/
94-
public boolean _____ = false;
95-
public boolean ______ = true;
96-
public String ___ = "You need to fill in the blank ___";
97-
public int ____ = 0;
98-
public Turtle _______ = new Turtle();
107+
public boolean _____ = false;
108+
public boolean ______ = true;
109+
public String ___ = "You need to fill in the blank ___";
110+
public int ____ = 0;
111+
public Turtle _______ = new Turtle();
99112
public Tortoise ________;
113+
public Topping _________ = Topping.NoTopping;
100114
public String ___()
101115
{
102116
return ___;

0 commit comments

Comments
 (0)