• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Calculation always comes out zero

gotenks05

Lurker
I am having some troubles with a program that I am trying to create. The program is supposed to do RMD calculations based on the age of the person, which is calculated by their given birth date, and the account balance, which is user supplied. My problem is that the results always come out as 0.0. The birth date is being accepted, since the age is being calculated and the balance is also accepted. How do I fix this?

The activity code looks like this:

Code:
package com.MinDis.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;

public class MinDis extends Activity
{
	String display;
	EditText date;
	EditText rmd;
	EditText balance;
	Button calc;
	RMD comp = new RMD();
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

	date = (EditText)findViewById(R.id.date);
	balance = (EditText)findViewById(R.id.amount);
	rmd = (EditText)findViewById(R.id.rmd);
	calc = (Button)findViewById(R.id.calculate);
	rmd.setEnabled(false);
    }

	public void rmdAction(View v) throws Exception
	{
		String day;
		String amount;

		amount = balance.getText().toString();
		day = date.getText().toString();

		comp.setBDate(day);
		comp.setBalance(Double.parseDouble(amount));
		rmd.setText(Double.toString(comp.getRMD()));

	}
}

It could be my problem, but I do not think it is.

This is my external class file, which I think is where the problem lies:

Code:
package com.MinDis.android;

import java.util.*;
import java.text.*;

public class RMD
{
	double balance;
	double rmd;
	long age;
	String bdate;
	SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yyyy");
	
	Date current = new Date();
	public void setBalance(double i)
	{
		balance = i;
	}

	public double getBalance()
	{
		return balance;
	}

	public void setBDate(String h)
	{
		bdate = h;
	}

	public long getAge() throws Exception
	{
		
		Date birthd = sd.parse(bdate);
		long cur;
		long birth;
		long diff;

		cur = current.getTime();
		birth = birthd.getTime();
		diff = cur - birth;
		age = (diff/(24*60*60*1000))/365;
		return age;
	}

	public double getRMD()
	{

		if (age == 70)
		{
			rmd = balance/27.4;
		}

		if (age == 71)
		{
			rmd = balance/26.5;
		}

		if (age == 72)
		{
			rmd = balance/25.6;
		}

		if (age == 73)
		{
			rmd = balance/24.7;
		}

		if (age == 74)
		{
			rmd = balance/23.8;
		}

		return rmd;
	}
}

I have tried using the compareTo() and equals() methods, but it results in either the same or the compiler thinks I am dereferencing a long.
 
Have you tried debugging it? That always helps me when i dont know where a problem is occuring.
 
Have you tried debugging it? That always helps me when i dont know where a problem is occuring.

I might try that. Also, I implemented the external class with a J2SE program and it gives the same results, so this is not limited to the Android platform, so I have 100% confirmation that my external class is where the problem is.

Update: I solved the problem.
 
Back
Top Bottom