Hello all!

I'm starting out and new to the development of android applications
and also new to the java programming.  I'm trying to make a app that
will allow me to calculate a loan but I am running into some trouble
and need assistance.  Having virtually 0 experience with java I
researched java code that I could use but it did not seem to convert,
I have went through and tried to changed most the of the what I
thought needed to be changed but eclipse does not seem to recognize
what a "parseDouble" is.  How can I make this code work? below is the
code that i have in my main java file:

package com.android.loancalc;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import com.project.calculator.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


public class main extends Activity
{
         double principal; // original principal

          double intRate; // interest rate

          double numYears; // length of loan in years

          final int payPerYear = 12;
          NumberFormat nf;

        public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final DecimalFormat df = new DecimalFormat ("#,###.##");

        final TextView txtAnswer =
                (TextView) findViewById(R.id.txt_payments);

        Button btCal = (Button) findViewById(R.id.bt_calc);

        btCal.setOnClickListener(new View.OnClickListener()

        {

                        public void onClick(View arg0)
                        {
                                double result = 0.0;

                                TextView amountStr = (TextView) 
findViewById(R.id.txt_pricipal);
                                TextView periodStr = (TextView) 
findViewById(R.id.txt_years);
                                TextView rateStr = (TextView) 
findViewById(R.id.txt_interest);

                                try {
                                        if (amountStr.length() != 0 && 
periodStr.length() != 0
                                                  && rateStr.length() != 0) {

                                                principal = 
Double.parseDouble(amountStr);
                                                numYears = 
Double.parseDouble(periodStr);
                                                intRate = 
Double.parseDouble(rateStr) / 100;

                                                result = compute();

                                                
txtAnswer.setText(nf.format(result));
                                        }

                        }
                                catch (NumberFormatException exc)
                                        {
                                                txtAnswer.setText("Opps");
                                                Log.v("myApp",exc.toString());
                                        }
                }


                double compute()
                        {
                                double numer;
                                double denom;
                                double b, e;

                            numer = intRate * principal / payPerYear;

                            e = -(payPerYear * numYears);
                            b = (intRate / payPerYear) + 1.0;

                            denom = 1.0 - Math.pow(b, e);

                            return numer / denom;
                        }
        });
    }
}


Thanks for the help!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to