|
| 1 | +var Westros; |
| 2 | +(function (Westros) { |
| 3 | + (function (Food) { |
| 4 | + var SimpleIngredient = (function () { |
| 5 | + function SimpleIngredient(name, calories, ironContent, vitaminCContent) { |
| 6 | + this.name = name; |
| 7 | + this.calories = calories; |
| 8 | + this.ironContent = ironContent; |
| 9 | + this.vitaminCContent = vitaminCContent; |
| 10 | + } |
| 11 | + SimpleIngredient.prototype.GetName = function () { |
| 12 | + return this.name; |
| 13 | + }; |
| 14 | + SimpleIngredient.prototype.GetCalories = function () { |
| 15 | + return this.calories; |
| 16 | + }; |
| 17 | + SimpleIngredient.prototype.GetIronContent = function () { |
| 18 | + return this.ironContent; |
| 19 | + }; |
| 20 | + SimpleIngredient.prototype.GetVitaminCContent = function () { |
| 21 | + return this.vitaminCContent; |
| 22 | + }; |
| 23 | + return SimpleIngredient; |
| 24 | + })(); |
| 25 | + Food.SimpleIngredient = SimpleIngredient; |
| 26 | + |
| 27 | + var CompoundIngredient = (function () { |
| 28 | + function CompoundIngredient(name) { |
| 29 | + this.name = name; |
| 30 | + this.ingredients = new Array(); |
| 31 | + } |
| 32 | + CompoundIngredient.prototype.AddIngredient = function (ingredient) { |
| 33 | + this.ingredients.push(ingredient); |
| 34 | + }; |
| 35 | + |
| 36 | + CompoundIngredient.prototype.GetName = function () { |
| 37 | + return this.name; |
| 38 | + }; |
| 39 | + CompoundIngredient.prototype.GetCalories = function () { |
| 40 | + var total = 0; |
| 41 | + for (var i = 0; i < this.ingredients.length; i++) { |
| 42 | + total += this.ingredients[i].GetCalories(); |
| 43 | + } |
| 44 | + return total; |
| 45 | + }; |
| 46 | + CompoundIngredient.prototype.GetIronContent = function () { |
| 47 | + var total = 0; |
| 48 | + for (var i = 0; i < this.ingredients.length; i++) { |
| 49 | + total += this.ingredients[i].GetIronContent(); |
| 50 | + } |
| 51 | + return total; |
| 52 | + }; |
| 53 | + CompoundIngredient.prototype.GetVitaminCContent = function () { |
| 54 | + var total = 0; |
| 55 | + for (var i = 0; i < this.ingredients.length; i++) { |
| 56 | + total += this.ingredients[i].GetVitaminCContent(); |
| 57 | + } |
| 58 | + return total; |
| 59 | + }; |
| 60 | + return CompoundIngredient; |
| 61 | + })(); |
| 62 | + Food.CompoundIngredient = CompoundIngredient; |
| 63 | + })(Westros.Food || (Westros.Food = {})); |
| 64 | + var Food = Westros.Food; |
| 65 | +})(Westros || (Westros = {})); |
0 commit comments