在第 3 课之后已为 MortgageCalculationService.egl 完成的代码

以下代码是完成第 3 课之后 MortgageCalculationService.egl 文件中的文本。
package services;

service MortgageCalculationService

   function amortize(inputData MortgageCalculationResult inOut)
      amt MONEY = inputData.loanAmount;

      // convert to monthly rate
      rate DECIMAL(10, 8) = (1 + inputData.interestRate / 1200);

      // convert to months
      term INT = (inputData.term * 12);

      // calculate monthly payment amount
      pmt MONEY = (amt * (rate - 1) * Mathlib.pow(rate, term)) 
         / (MathLib.pow(rate, term) - 1);
      totalInterest MONEY = (pmt * term) - amt;

      // update result record
      inputData.monthlyPayment = pmt;
      inputData.interest = totalInterest;
   end
end

record MortgageCalculationResult

   // user input
   loanAmount MONEY;
   interestRate DECIMAL(10,8);
   term INT;

   // calculated fields
   monthlyPayment MONEY;
   interest MONEY;
end

反馈