CSCI 490E/680K Assignment 2 - Android Programming - Spring 2012

02/14/2012


Write an Android app that performs a Mortgage calculation given user input.  The user will enter

It will contain two buttons, one to perform the calculations and display the results and the other to clear the text of all the text input/display boxes.

The displayed results will be

Use embedded TableLayout(s) to help format the label-amount pairs.

In addition, there will be a text box at the bottom for error messages (for example, missing data).

These last three text boxes should not allow user input. 

The first three should only allow numeric values to be input (with a decimal point if desired).

Numeric output should be formatted (rounded) to two decimal places (dollars and cents).  See below.

Finally, develop and implement an alternate landscape-mode layout for this app, rearranging the widgets to fit better on the horizontal screen.  Note that Ctrl-F12 will toggle between the two orientations in an emulator.

Monthly Payment Formula

The formula for the monthly payment on a loan is:

                  J
 M = P * ----------------------
           1 - (1 + J) ** -N
 
M = monthly payment
P = principle = amount borrowed
I = annual interest rate (1 to 100)
N = number of months of loan = number_of_years*12
J = monthly interest in decimal form = I/(1200)
** = exponentiation operator - not available in Java, so...

To calculate a number to a power, look up and use Math.pow().

Just for checking: the monthly payment on $1000 for 30 years at 6% is $5.9955... ($6.00 rounded to 2 decimal places) and $2158.38 total repayment.

Total Amount of Mortgage Payments

This is simply the monthly payment times 12 times the number of years.

Numeric Output Formatting

Floating point numeric output in a text box or log will display decimal places - but you can't control how many without some work. One technique to control the number of decimal places displayed is by making use of a special Java class.  Do the following:

1. import java.text.DecimalFormat;

2. Create a DecimalFormat object as follows:

DecimalFormat df = new DecimalFormat("#.00");  // for 2 decimal places

3. When you want to display a number, pass it to the format() method of this object:

aTextBox.setText("Number is " + df.format(adouble));  // or anything that wants a String

The format() method takes a double and returns a String, which is the text representation of the double's value, formatted as specified in the constructor of the DecimalFormat object.