07.01.2013 Views

David Defour - Université de Perpignan

David Defour - Université de Perpignan

David Defour - Université de Perpignan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java, Continued<br />

(LoanCalculatorActivity.java)<br />

private void calculateAndSetOutputValues() {<br />

PaymentInfo paymentInfo =<br />

new PaymentInfo(mLoanAmount, mAnnualInterestRateInPercent,<br />

mLoanPeriodInMonths, mCurrencySymbol);<br />

TextView loanAmountDisplay = (TextView)findViewById(R.id.loan_amount);<br />

loanAmountDisplay.setText(paymentInfo.getFormattedLoanAmount());<br />

TextView interestRateDisplay =<br />

(TextView)findViewById(R.id.interest_rate);<br />

interestRateDisplay.setText<br />

(paymentInfo.getFormattedAnnualInterestRateInPercent());<br />

TextView loanPeriodDisplay = (TextView)findViewById(R.id.loan_period);<br />

loanPeriodDisplay.setText(paymentInfo.getFormattedLoanPeriodInMonths());<br />

TextView monthlyPaymentDisplay =<br />

(TextView)findViewById(R.id.monthly_payment);<br />

monthlyPaymentDisplay.setText(paymentInfo.getFormattedMonthlyPayment());<br />

TextView totalPaymentsDisplay =<br />

(TextView)findViewById(R.id.total_payments);<br />

totalPaymentsDisplay.setText(paymentInfo.getFormattedTotalPayments());<br />

}<br />

362<br />

jeudi 26 janvier 12<br />

The math is done in the PaymentInfo class (next sli<strong>de</strong>s) at the top of the method,<br />

which in turn calls the LoanUtils class (following sli<strong>de</strong>s). The rest of the co<strong>de</strong> just<br />

assigns the output values to the TextViews that are in the second column of the table<br />

from the layout file (res/layouts/loan_payments.xml).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!