class Pizza { boolean thinCrust; String sauce; Topping top; Pizza( boolean thinCrust, String sauce, Topping top) { this.thinCrust = thinCrust; this.sauce = sauce; this.top = top; } //new Pizza(true, "red", new Pepperoni(15)).price() -> 7.5 //To caluclate the price of this Pizza double price() { // ... this.thinCrust ... this.sauce ... this.top.ToppingMethod() return 6.0 + this.top.price(); } //new Pizza(true, "red", new Pepperoni(15)).profit() -> 4.0 //To calculate the profit made from this Pizza double profit() { // ... this.thinCrust .. this.sauce ... this.top.ToppingMethod() return this.price() - this.cost(); } //new Pizza(true, "red", new Pepperoni(15)).cost() -> 3.5 //To calculate the cost of this Pizza double cost() { // ... this.thinCrust ... this.sauce ... this.top.ToppingMethod() return 2.0 + this.top.cost(); } //new Pizza(true,"white",new ExtraCheese(5)).ownersFav() == true //new Pizza(false,"red",new Pepperoni(20)).ownersFav() == false //To determine if this Pizza is the owners favorite kind boolean ownersFav() { // this.thinCrust ... this.sauce ... this.top.ToppingMethod return this.thinCrust && this.sauce.equalsIgnoreCase("white") && this.top.ownersFav(); } //new Pizza(true, "white", new ExtraCheese(5)).wrongTop(new Chicken(12)) => // new Pizza(true, "white", new Chicken(12)) //To produce a pizza, like this Pizza, but with the given topping Pizza wrongTop( Topping givenTopping) { // ... this.thinCrust ... this.sauce ... this.top.toppingMethod() return new Pizza(this.thinCrust, this.sauce , givenTopping); } } abstract class Topping { //to report the price of this topping abstract double price(); //To calcualte the cost of this Topping abstract double cost(); //To report whether or not this Topping is the owners favorite abstract boolean ownersFav(); } class Pepperoni extends Topping { int slices; Pepperoni( int slices ) { this.slices = slices; } //to report the price of this Pepperoni //new Pepperoni(15).price() => 1.5 double price() { //... this.slices ... return 1.5; } //To calcualte the cost of this Pepperoni //new Pepperoni(15).cost() -> 1.5 double cost() { // ... this.slices ... return this.slices * .1; } //To report whether or not this Topping is the owners favorite //new Pepperoni(15).ownersFav() == false boolean ownersFav() { // ... this.slices ... return false; } } class GreenPepper extends Topping { double amount; GreenPepper( double amount ) { this.amount = amount; } //to report the price of this GreenPepper //new GreenPepper(1.5).price() => 1 double price() { //... this.amount ... return 1; } //To calcualte the cost of this GreenPepper //new GreenPepper(1.5).cost() -> .75 double cost() { // ... this.amount ... return this.amount * .5; } //To report whether or not this Topping is the owners favorite //new GreenPepper(1.5).ownersFav() == false boolean ownersFav() { // ... this.amount ... return false; } } class ExtraCheese extends Topping { int ounces; ExtraCheese( int ounces ) { this.ounces = ounces; } //to report the price of this ExtraCheese //new ExtraCheese(5).price() => .5 double price() { //... this.ounces ... return .5; } //To calcualte the cost of this ExtraCheese //new ExtraCheese(5).cost() -> .5 double cost() { // ... this.ounces ... return this.ounces * .1; } //To report whether or not this Topping is the owners favorite //new ExtraCheese(5).ownersFav() == true boolean ownersFav() { // ... this.ounces ... return true; } } class Chicken extends Topping { int numPieces; Chicken( int numPieces ) { this.numPieces = numPieces; } //to report the price of this Chicken //new Chicken(15).price() => 1.45 double price() { //... this.numPieces ... return 1.45; } //To calcualte the cost of this Chicken //new Chicken(15).cost() -> .9 double cost() { // ... this.numPieces ... return this.numPieces * .06; } //To report whether or not this Topping is the owners favorite //new Chicken(15).ownersFav() == false boolean ownersFav() { // ... this.numPieces ... return false; } }