Le code suivant est le texte du fichier MortgageCalculationService.egl à la fin de la leçon 3.
package services;
service MortgageCalculationService
function amortize(inputData MortgageCalculationResult inOut)
amt MONEY = inputData.loanAmount;
// convertir en taux mensuel
rate DECIMAL(10, 8) = (1 + inputData.interestRate / 1200);
// convertir en mois
term INT = (inputData.term * 12);
// calcul du montant du paiement mensuel
pmt MONEY = (amt * (rate - 1) * Mathlib.pow(rate, term))
/ (MathLib.pow(rate, term) - 1);
totalInterest MONEY = (pmt * term) - amt;
// mise à jour de l'enregistrement du résultat
inputData.monthlyPayment = pmt;
inputData.interest = totalInterest;
end
end
record MortgageCalculationResult
// saisie de l'utilisateur
loanAmount MONEY;
interestRate DECIMAL(10,8);
term INT;
// zones calculées
monthlyPayment MONEY;
interest MONEY;
end