Exemple #1
0
 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());
     }
   }
 }
Exemple #2
0
  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());
  }
Exemple #3
0
  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) {
    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());
  }
Exemple #5
0
 public double cost() {
   double cost = beverage.cost();
   int size = getSize();
   if (size == Beverage.TALL) {
     cost += 1.00;
   } else if (size == Beverage.GRANDE) {
     cost += 2.00;
   } else {
     cost += 3.00;
   }
   return cost;
 }
  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);
  }
Exemple #7
0
  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());
  }
Exemple #8
0
  public double cost() {
    double cost = beverage.cost();

    if (getSize() == Size.TALL) {
      System.out.print("TALL ");
      cost += 0.10;
    } else if (getSize() == Size.GRANDE) {
      System.out.print("GRANDE ");
      cost += 0.15;
    } else if (getSize() == Size.VENTI) {
      System.out.print("VENTI ");
      cost += 0.20;
    }

    return cost;
  }
Exemple #9
0
 public double cost() {
   if (beverage.getSize() == 1) {
     return 0.2 + beverage.cost();
   } else if (beverage.getSize() == 2) {
     return 0.3 + beverage.cost();
   } else if (beverage.getSize() == 3) {
     return 0.4 + beverage.cost();
   } else {
     return 0;
   }
 }
Exemple #10
0
 @Override
 public double cost() {
   return beverage.cost() + 0.10;
 }
Exemple #11
0
 // 此接口是继承自抽象组件Beverage的cos方法
 @Override
 public double cost() {
   return 0.5 + beverage.cost();
 }
 // First we delegate the call to the object we're decorating, so that it can
 // compute the cost, and then add the cost of this condiment to the result
 public double cost() {
   return beverage.cost() + 1.00;
 }
Exemple #13
0
 public int getSize() {
   return beverage.getSize();
 }
 @Override
 public double cost() {
   return PRICE + mBenverage.cost();
 }
Exemple #15
0
 public Size getSize() {
   return beverage.getSize();
 }
Exemple #16
0
 @Override
 public double cost() {
   return 2 + be.cost();
 }
Exemple #17
0
 @Override
 public String getDescription() {
   return beverage.getDescription() + ", Milk";
 }
 public String getDescription() {
   return beverage.getDescription() + " Soy";
 }
 @Override
 public String getDescription() {
   return mBenverage.getDescription() + "Soy";
 }
Exemple #20
0
 public String getDescription() // interface of CondimentDecorator
     {
   return beverage.getDescription() + ", MOCHA";
 }
Exemple #21
0
 public Mocha(Beverage beverage) {
   this.beverage = beverage;
   System.out.println("Mocha is created with size=" + beverage.getSize());
 }
Exemple #22
0
 public int getSize() // interface of CondimentDecorator
     {
   return beverage.getSize();
 }
 public double cost() {
   return beverage.cost() + .15;
 }
 public int cost() {
   return 5 + beverage.cost();
 }
Exemple #25
0
 @Override
 public double cost() {
   return beverage.cost() + .12;
 }
Exemple #26
0
  public static void main(String[] args) {

    Beverage drank = new Sugar(new Chocolate(new Milk(new Coffee())));

    System.out.println(drank.cost());
  }
Exemple #27
0
 @Override
 public String getDescript() {
   return be.getDescript() + ", Milk";
 }
Exemple #28
0
 @Override
 public BigDecimal cost() {
   return beverage.cost().add(this.cost);
 }
Exemple #29
0
 @Override
 public String getDescription() {
   return beverage.getDescription() + " with " + this.description;
 }
Exemple #30
0
 public String getDescription() {
   return beverage.getDescription() + ", Mocha";
 }