El código siguiente es el texto del archivo MortgageCalculationService.egl al final de la Lección 3.
package services;
service MortgageCalculationService
function amortize(inputData MortgageCalculationResult inOut)
amt MONEY = inputData.loanAmount;
// convertir a tipo mensual
rate DECIMAL(10, 8) = (1 + inputData.interestRate / 1200);
// convertir a meses
term INT = (inputData.term * 12);
// calcular importe de la cuota mensual
pmt MONEY = (amt * (rate - 1) * Mathlib.pow(rate, term))
/ (MathLib.pow(rate, term) - 1);
totalInterest MONEY = (pmt * term) - amt;
// actualizar registro de resultado
inputData.monthlyPayment = pmt;
inputData.interest = totalInterest;
end
end
record MortgageCalculationResult
// entrada de usuario
loanAmount MONEY;
interestRate DECIMAL(10,8);
term INT;
// campos calculados
monthlyPayment MONEY;
interest MONEY;
end