public static void main(String[] args) { Beverage expresso = new Expresso(); System.out.println(expresso.getDescription()); System.out.println(expresso.cost()); Beverage milk = new Milk(expresso); System.out.println(milk.getDescription()); System.out.println(milk.cost()); Beverage mocha = new Mocha(milk); System.out.println(mocha.getDescription()); System.out.println(mocha.cost()); }
public void prepare(Beverage b) { if (b.getBeverage() == null) System.out.println("Add Coffee\nAdd Water"); else { if (b.getDescription().equals("milk")) { System.out.println("Steaming milk"); prepare(b.getBeverage()); System.out.println("Mixing milk and coffee"); } else { prepare(b.getBeverage()); System.out.println("Adding " + b.getDescription()); } } }
public static void main(String[] args) { Beverage beverage = new NongSuoCoffee(); System.out.println(beverage.getDescription() + " | " + beverage.cost()); Beverage beverage2 = new XingBingLe(); beverage2 = new MochaDecorator(beverage2); beverage2 = new MochaDecorator(beverage2); beverage2 = new MilkDecorator(beverage2); System.out.println(beverage2.getDescription() + " | " + beverage2.cost()); Beverage beverage3 = new XingBingLe(); beverage3 = new MilkDecorator(beverage3); System.out.println(beverage3.getDescription() + " | " + beverage3.cost()); }
public static void main(String[] args) { // Espresso Beverage espresso = new Espresso(); System.out.println(espresso.getDescription() + " : $" + espresso.cost()); // DarkRoast + Mocka + Mocha + Whip Beverage darkRoast = new DarkRoast(); darkRoast = new Mocha(darkRoast); darkRoast = new Mocha(darkRoast); darkRoast = new Whip(darkRoast); System.out.println(darkRoast.getDescription() + " : $" + darkRoast.cost()); // HouseBlend + Soy + Mocha + Whip Beverage houseblend = new HouseBlend(); houseblend = new Soy(houseblend); houseblend = new Mocha(houseblend); houseblend = new Whip(houseblend); System.out.println(houseblend.getDescription() + " : $" + houseblend.cost()); }
public static void main(String[] args) { DarkRoast darkRoast = new DarkRoast(); System.out.println( "Beverage: \t" + darkRoast.getDescription() + ", Cost: \t" + darkRoast.getCost()); Milk milk = new Milk(darkRoast); System.out.println("Beverage: \t" + milk.getDescription() + ", Cost: \t" + milk.getCost()); System.out.println("\n##########################################\n"); Beverage beverage = new HouseBlend(); beverage = new Milk(beverage); beverage = new Milk(beverage); beverage = new Milk(beverage); beverage = new Milk(beverage); beverage = new Mocha(beverage); System.out.println( "Beverage: \t" + beverage.getDescription() + ", Cost: \t" + beverage.getCost()); }
public void onGetCostClick(View view) { double cost; String description = ""; Beverage beverage = null; RadioGroup rg = (RadioGroup) findViewById(R.id.beverageType); switch (rg.getCheckedRadioButtonId()) { case R.id.rbEspresso: beverage = new Espresso(); break; case R.id.rbHouseBlend: beverage = new HouseBlend(); } if (((Switch) (findViewById(R.id.swWhip))).isChecked()) { beverage = new Whip(beverage); } if (((Switch) (findViewById(R.id.swSoy))).isChecked()) { beverage = new Soy(beverage); } if (((Switch) (findViewById(R.id.swMocha))).isChecked()) { beverage = new Mocha(beverage); } if (beverage != null) { String order = "You ordered: " + beverage.getDescription() + ", which costs: " + Double.toString(beverage.cost()); Toast.makeText(this, order, Toast.LENGTH_SHORT).show(); } Intent intent = new Intent(this, MyService.class); sendBroadcast(intent); }
@Override public String getDescription() { return beverage.getDescription() + ", Milk"; }
public String getDescription() { return beverage.getDescription() + " Soy"; }
@Override public String getDescription() { return beverage.getDescription() + " with " + this.description; }
public String getDescription() // interface of CondimentDecorator { return beverage.getDescription() + ", MOCHA"; }
@Override public String getDescription() { return mBenverage.getDescription() + "Soy"; }
public String getDescription() { return beverage.getDescription() + ", Mocha"; }