You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
5.1 KiB
JavaScript
127 lines
5.1 KiB
JavaScript
6 years ago
|
// Abstract PriceCalculator
|
||
|
var AbstractPriceCalculator = function (){};
|
||
|
AbstractPriceCalculator.prototype = {
|
||
|
calculation_price : function(){}
|
||
|
}
|
||
|
|
||
|
// Adults Price Calculator
|
||
|
var AdultsPriceCalculator = function(){};
|
||
|
AdultsPriceCalculator.prototype = new AbstractPriceCalculator();
|
||
|
AdultsPriceCalculator.prototype.calculation_price = function(Num, Price){
|
||
|
return Num * Price;
|
||
|
};
|
||
|
|
||
|
// Children Price Calculator
|
||
|
var ChildrenPriceCalculator = function(){}
|
||
|
ChildrenPriceCalculator.prototype = new AbstractPriceCalculator();
|
||
|
ChildrenPriceCalculator.prototype.calculation_price = function(Num, Price){
|
||
|
return Num * (Price * 0.75);
|
||
|
};
|
||
|
|
||
|
// Babies Price Calculator
|
||
|
var BabiesPriceCalculator = function(){};
|
||
|
BabiesPriceCalculator.prototype = new AbstractPriceCalculator();
|
||
|
BabiesPriceCalculator.prototype.calculation_price = function(Num, Price){
|
||
|
return Num * (Price * 0.10);
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
// Abstract Price Difference
|
||
|
var AbstractPriceDifference = function(){
|
||
|
//this.init.apply(this,arguments);
|
||
|
};
|
||
|
AbstractPriceDifference.prototype = {
|
||
|
number_people : 0,
|
||
|
price : 0,
|
||
|
extra : 0,
|
||
|
calculation_price : function(){}
|
||
|
};
|
||
|
|
||
|
var OddPriceDifference = function(){};
|
||
|
OddPriceDifference.prototype = new AbstractPriceDifference();
|
||
|
OddPriceDifference.prototype.calculation_price = function(ObjPriceCalculator){
|
||
|
var temp_price = 0;
|
||
|
var temp_Difference_price = 1 * this.price * 1.75;
|
||
|
if (this.number_people > 0){
|
||
|
if (this.number_people - this.extra > 0){
|
||
|
temp_price = ObjPriceCalculator.calculation_price((this.number_people - this.extra) * 2, this.price) + temp_Difference_price;
|
||
|
}else{
|
||
|
temp_price = this.number_people * temp_Difference_price;
|
||
|
}
|
||
|
}
|
||
|
return temp_price;
|
||
|
};
|
||
|
|
||
|
var EvenPriceDifference = function(){};
|
||
|
EvenPriceDifference.prototype = new AbstractPriceDifference();
|
||
|
EvenPriceDifference.prototype.calculation_price = function(ObjPriceCalculator){
|
||
|
var temp_price = 0;
|
||
|
temp_price = ObjPriceCalculator.calculation_price(this.number_people, this.price);
|
||
|
return temp_price;
|
||
|
};
|
||
|
|
||
|
//Abstract Product Manager
|
||
|
var AbstractProductManager = function(){};
|
||
|
AbstractProductManager.prototype = {
|
||
|
adults_people : 0,
|
||
|
children_people : 0,
|
||
|
babies_people : 0,
|
||
|
price : 0,
|
||
|
extra : 0,
|
||
|
calculation_price : function(){}
|
||
|
};
|
||
|
var CruiseProductManager = function(){};
|
||
|
CruiseProductManager.prototype = new AbstractProductManager();
|
||
|
CruiseProductManager.prototype.calculation_price = function(ObjAbstractPriceDifference_array, ObjAbstractPriceCalculator_array){
|
||
|
|
||
|
var obj_price_difference = null;
|
||
|
var adults_price = 0, children_price = 0, babies_price = 0, total_prices = 0;
|
||
|
var selectType = 0;
|
||
|
selectType = (this.adults_people + this.children_people + this.babies_people) / 2 ;
|
||
|
if (this.extra <= selectType) {
|
||
|
obj_price_difference = ObjAbstractPriceDifference_array[0];
|
||
|
obj_price_difference.price = this.price;
|
||
|
obj_price_difference.number_people = this.adults_people;
|
||
|
adults_price = obj_price_difference.calculation_price(ObjAbstractPriceCalculator_array[0]);
|
||
|
obj_price_difference.number_people = this.children_people;
|
||
|
children_price = obj_price_difference.calculation_price(ObjAbstractPriceCalculator_array[1]);
|
||
|
obj_price_difference.number_people = this.babies_people;
|
||
|
babies_price = obj_price_difference.calculation_price(ObjAbstractPriceCalculator_array[2]);
|
||
|
total_prices = adults_price + children_price + babies_price;
|
||
|
|
||
|
}else if(this.extra > selectType) {
|
||
|
obj_price_difference = ObjAbstractPriceDifference_array[1];
|
||
|
obj_price_difference.price = this.price;
|
||
|
obj_price_difference.extra = this.extra;
|
||
|
obj_price_difference.number_people = this.adults_people;
|
||
|
adults_price = obj_price_difference.calculation_price(ObjAbstractPriceCalculator_array[0]);
|
||
|
obj_price_difference.number_people = this.children_people;
|
||
|
children_price = obj_price_difference.calculation_price(ObjAbstractPriceCalculator_array[1]);
|
||
|
//alert(children_price);
|
||
|
obj_price_difference.number_people = this.babies_people;
|
||
|
babies_price = obj_price_difference.calculation_price(ObjAbstractPriceCalculator_array[2]);
|
||
|
total_prices = adults_price + children_price + babies_price;
|
||
|
}
|
||
|
ObjAbstractPriceDifference_array[0] = null;
|
||
|
ObjAbstractPriceDifference_array[1] = null;
|
||
|
ObjAbstractPriceCalculator_array[0] = null;
|
||
|
ObjAbstractPriceCalculator_array[1] = null;
|
||
|
ObjAbstractPriceCalculator_array[2] = null;
|
||
|
return total_prices;
|
||
|
};
|
||
|
|
||
|
var PackageProductManager = function(){};
|
||
|
PackageProductManager.prototype = new AbstractProductManager();
|
||
|
PackageProductManager.prototype.calculation_price = function(ObjAbstractPriceCalculator_array){
|
||
|
var adults_price = 0, children_price = 0, babies_price = 0, total_prices = 0;
|
||
|
adults_price = ObjAbstractPriceCalculator_array[0].calculation_price(this.adults_people, this.price);
|
||
|
children_price = ObjAbstractPriceCalculator_array[1].calculation_price(this.children_people, this.price);
|
||
|
babies_price = ObjAbstractPriceCalculator_array[2].calculation_price(this.babies_people, this.price);
|
||
|
total_prices = adults_price + children_price + babies_price;
|
||
|
ObjAbstractPriceCalculator_array[0] = null;
|
||
|
ObjAbstractPriceCalculator_array[1] = null;
|
||
|
ObjAbstractPriceCalculator_array[2] = null;
|
||
|
return total_prices;
|
||
|
};
|