I am trying to work on an Android app, but I am having troubles. The program calculates the age of the person depending on their birth date and current date, then figure the RMD value. The program is accepting the birth date and the balance, because those show up fine, but the RMD value always comes to zero. Now, before you guys go saying "Go somewhere else. We don't deal with Android programming", I have verified that this is a problem in J2SE as well. The age and RMD values are calculated in an external class and when I tested out the external class with a desktop program, it gives me the same results as the Android app, which means the problem is definitely in my external class and it is a Java problem, not an Android platform exclusive problem. How do I fix this, so that the RMD shows the correct results, instead of "0.0"?
Here is the external class source:
Yes, I have tried the equals and the compareTo() methods. They either returned the same results or complained that I was trying to dereference a long variable.
Here is the external class source:
Code:
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;
}
}
Yes, I have tried the equals and the compareTo() methods. They either returned the same results or complained that I was trying to dereference a long variable.