// Discrete Compounding Formulas with Discrete Payments 

function DiscretePayments(type, v, i, n){
	this.type = type;
	this.v = v;
	this.i = i;
	this.n = n;
}

// returns result
DiscretePayments.prototype.result = function(){
	msg = "";
	if (this.type == "FP") msg = this.v * Math.pow((1 + this.i), this.n);
	if (this.type == "PF") msg = this.v / Math.pow((1 + this.i), this.n);
	if (this.type == "FA") msg = this.v * (Math.pow((1 + this.i), this.n) - 1)/this.i;
	if (this.type == "AF") msg = this.v * this.i/(Math.pow((1 + this.i), this.n) - 1);
	if (this.type == "PA") msg = this.v * (Math.pow((1 + this.i), this.n) - 1)/(this.i*(Math.pow((1 + this.i), this.n)));
	if (this.type == "AP") msg = this.v * (this.i * Math.pow((1 + this.i), this.n))/(Math.pow((1 + this.i), this.n) - 1);
	return msg;
}
// returns input values
DiscretePayments.prototype.inputData = function(){
	return this.type + " " + this.v + " " + this.i + " " + this.n;
}

// Copyright engineeringtoolbox.com