[android-developers] Eclipse Loan calculator help!

2011-04-15 Thread Jester
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Eclipse Loan calculator help!

2011-04-15 Thread TreKing
On Thu, Apr 14, 2011 at 1:06 AM, Jester  wrote:

> 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.
>

If you have "virtually 0 experience with java", then you need to stop and go
learn Java. Randomly changing code samples without understanding the changes
you're making isn't going to get you very far.


> How can I make this code work?
>

To be perfectly frank: learn Java. This is a simple Java problem and
moreover has nothing to do with Android specifically.
Once you have a better grasp of the language you will understand why Eclipse
does not recognize "parseDouble".

I'll also suggest you learn to use Eclipse itself, for not only will it tell
you exactly what the problem is, but usually offers suggestions on how to
fix it and often does so automatically for you on the spot.

Good luck.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

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

Re: [android-developers] Eclipse Loan calculator help!

2011-04-15 Thread Android K
What is the error that you get?

On Thu, Apr 14, 2011 at 2:06 AM, Jester  wrote:

> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

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