Skip to content
Snippets Groups Projects
Commit dc32fb47 authored by Peter Hertkorn's avatar Peter Hertkorn
Browse files

Add constructor injection in franchise

parent 7c0cb856
No related merge requests found
package pizzeria;
public class PizzaFranchise {
private PizzaStore store;
public PizzaFranchise(PizzaStore store) {
this.store = store;
}
public Pizza orderPizza(String type) {
return store.orderPizza(type);
}
}
......@@ -3,31 +3,17 @@ package pizzeria;
public class PizzaTestDrive {
public static void main(String[] args) {
PizzaStore nyStore = new NYPizzaStore();
PizzaStore chicagoStore = new ChicagoPizzaStore();
Pizza pizza = nyStore.orderPizza("cheese");
System.out.println("Ethan ordered a " + pizza.getName() + "\n");
pizza = chicagoStore.orderPizza("cheese");
System.out.println("Joel ordered a " + pizza.getName() + "\n");
pizza = nyStore.orderPizza("clam");
System.out.println("Ethan ordered a " + pizza.getName() + "\n");
pizza = chicagoStore.orderPizza("clam");
System.out.println("Joel ordered a " + pizza.getName() + "\n");
pizza = nyStore.orderPizza("pepperoni");
System.out.println("Ethan ordered a " + pizza.getName() + "\n");
pizza = chicagoStore.orderPizza("pepperoni");
System.out.println("Joel ordered a " + pizza.getName() + "\n");
pizza = nyStore.orderPizza("veggie");
System.out.println("Ethan ordered a " + pizza.getName() + "\n");
pizza = chicagoStore.orderPizza("veggie");
System.out.println("Joel ordered a " + pizza.getName() + "\n");
PizzaStore[] storeList = {new TestPizzaStore(), new NYPizzaStore(), new ChicagoPizzaStore()};
String[] customerList = {"Ethan", "Joel", "Martha"};
String[] pizzaType = {"cheese", "veggie"};
for (int i=0; i<storeList.length; i++) {
PizzaFranchise franchise = new PizzaFranchise(storeList[i]);
for (int j=0; j<pizzaType.length; j++) {
Pizza pizza = franchise.orderPizza(pizzaType[j]);
System.out.println(customerList[i] + " ordered a " + pizza.getName() + "\n");
}
}
}
}
package pizzeria;
public class TestCheesePizza extends Pizza {
public TestCheesePizza() {
name = "Test Cheese Pizza";
dough = "Test Dough";
sauce = "Test Sauce";
toppings.add("Testing cheese toppings");
}
}
package pizzeria;
public class TestPizzaStore extends PizzaStore {
Pizza createPizza(String item) {
if (item.equals("cheese")) {
return new TestCheesePizza();
} else if (item.equals("veggie")) {
return new TestVeggiePizza();
} else return null;
}
}
package pizzeria;
public class TestVeggiePizza extends Pizza {
public TestVeggiePizza() {
name = "Test Veggie Pizza";
dough = "Test Dough";
sauce = "Test Sauce";
toppings.add("Testing veggie toppings");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment