Listing 1

@Service(LoanApproval.class) // Service declaration
public class LoanApprovalImpl implements LoanApproval {
    // Reference declarations using a protected or public field
    @Reference
    public  RiskAssessment riskAssessment;
 
    @Reference
    public  MortgageCalculator mortgageCalculator;

    @Reference
    protected InterestRateQuote interestRateQuote;
 
    // Reference declaration using a setter method
    private CreditCheck creditCheck;
 
    @Reference
    public void setCreditCheck(CreditCheck creditCheck) {
        this.creditCheck = creditCheck;
    }
 
    public boolean approve(Customer customer, double loanAmount, int years) {
        int score = creditCheck.getCreditScore(customer.getSsn());
        if (score < minimumCreditScore) {
            return false;
        }
        float rate = interestRateQuote.getRate(customer.getState(), loanAmount, years);
        double monthlyPayment = mortgageCalculator.getMonthlyPayment(loanAmount, years, rate);
        double ratio = monthlyPayment/customer.getMonthlyIncome();
        return riskAssessment.assess(score, ratio);
    }
}