예제 #1
0
 public function __construct()
 {
     // Create a new Lunch
     $Lunch = new Sandwich();
     // Print a description of this Lunch
     print $Lunch->getDescription() . " \$" . $Lunch->price() . "\n";
     // Create another Lunch
     $Lunch2 = new Burrito();
     // Add Cheese
     $Lunch2 = new Cheese($Lunch2);
     // Add Veggies
     $Lunch2 = new Veggies($Lunch2);
     // Print a description of this Lunch
     print $Lunch2->getDescription() . " \$" . $Lunch2->price() . "\n";
     // Create a third Lunch
     $Lunch3 = new PadThai();
     // Add Tofu
     $Lunch3 = new Tofu($Lunch3);
     // Add Cheese
     $Lunch3 = new Cheese($Lunch3);
     // Add Veggies
     $Lunch3 = new Veggies($Lunch3);
     // Print a description of this Lunch
     print $Lunch3->getDescription() . " \$" . $Lunch3->price() . "\n";
 }
예제 #2
0
    {
        echo 'Ingredientes:' . "\n";
        foreach ($this->getIngredients() as $ingredient) {
            echo get_class($ingredient) . "\n";
        }
    }
    public function bite($grams)
    {
        $bite = $this->weigth - $grams;
        if ($bite > 0) {
            $this->setWeigth($bite);
        } else {
            $this->setWeigth(0);
        }
        return $grams;
    }
}
$snd = new Sandwich($ingredients = null, $breadType = 'Miga');
echo 'Sandwich Basico' . "\n";
$snd->getDescription();
$snd->addIngredient('Butter');
$snd->addIngredient('Cheese');
$snd->addIngredient('RawHam');
echo 'Sandwich Con Tres Ingredientes' . "\n";
$snd->getDescription();
echo 'Luego de una mordida de 30 gr' . "\n";
$snd->bite(30);
$snd->getDescription();
echo 'Luego de una mordida de 50 gr' . "\n";
$snd->bite(50);
$snd->getDescription();