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

02/19/2012


Overview

For this assignment, you will add functionality to Assignment 2 to calculate the interest earned on an investment.  This will be done via an Android tabbed layout, so the user can switch between the two calculation types, seeing only one at a time.

The screen will consist of two tabs at the top of the screen (vertical orientation), one for Borrow calculations (where you get a loan, for example, a mortgage) and one for Investment calculations (lending; for example, a savings account). Clicking on one tab or the other will cause one of two screen layouts to appear.  The Borrow calculations will be identical to those in Assignment 2 (where it was called a Mortgage Calculator). The two screens will be similar, but different in some details.  (Note you are not required to do landscape orientation screens for this assignment.)

Borrow

(TextView) "Amount:"
(EditText) amount-input with hint: "amount to borrow"
(TextView) "Rate:"
(EditText) rate-input with hint: "interest rate %"
(TextView) "Time:"
(EditText) time-input with hint: "time in years"
(Button)   "Calculate"
(Button)   "Clear"
(TextView) "Monthly payment:"
(EditText) results-display (disabled, no hint)
(TextView) "Total payment:"
(EditText) results-display (disabled, no hint)
(EditText) error-message (disabled, no hint)

Invest

(TextView) "Amount:"
(EditText) amount-input with hint: "amount to invest"
(TextView) "Rate:"
(EditText) rate-input with hint: "interest rate %"
(TextView) "Time:"
(EditText) time-input with hint: "time in years"
(Button)   "Calculate"
(Button)   "Clear"
(TextView) "Final value:"
(EditText) results-display (disabled, no hint)
(EditText) error-message (disabled, no hint)

Numeric input fields should allow only decimal number input. Results-display fields should show results to 2 decimal places and should not allow user input.  Devise well-organized and logical screen layouts.

Implementation

Techniques to implement the Android tabbed layout will be covered in class.  Implement this as an app derived from TabActivity. Each calculation type will be a custom Activity-derived class which is stored as a separate .java file and which will define its own instance variables and methods. Each will have its own separate xml file to describe just its own layout.  Be sure to remember that as you add new classes to an Android application, you need to add an entry for each in the manifest file.

Formulae

Again, for Part A (the Borrow function) the formula for the monthly payment on a loan or mortgage 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 use use Math.pow().

The total amount to be paid over the life of the loan or mortgage is simply the monthly payment times 12 times the number of years.

For Part B, the final value of an Investment, the formula for (principle plus interest on principle (using compound interest)) is:

FV = P * (1 + I/100) ** T
 
FV = final value of investment
P  = principle = amount invested
I  = annual interest rate (1 to 100)
T  = time in years
** = exponentiation operator