I am working through a tutorial on calculating how old a person is.
1. I Convert inputed values into this format: YYYYMMDD
2. Subtract the birth information from the current information
3. The first three digits of your answer is the person's age. (Note that in most cases the first digit will be zero)
Example:
Birth: 19900510
Current: 20100803
Current - Birth : 0200293
First 3 Digits: 020
This person is 20 years old.
I named my function ageCalculator and the parameters as birthYear, curYear, birthMonth, curMonth, birthDay, curDay in that order.
I have written most of the function below. I just need to fill in the return statement. I do not know how to write the return statement to Drop the leading zero and look at digits 1 and 2. (see above)
any suggestions? Thank you
1. I Convert inputed values into this format: YYYYMMDD
2. Subtract the birth information from the current information
3. The first three digits of your answer is the person's age. (Note that in most cases the first digit will be zero)
Example:
Birth: 19900510
Current: 20100803
Current - Birth : 0200293
First 3 Digits: 020
This person is 20 years old.
I named my function ageCalculator and the parameters as birthYear, curYear, birthMonth, curMonth, birthDay, curDay in that order.
I have written most of the function below. I just need to fill in the return statement. I do not know how to write the return statement to Drop the leading zero and look at digits 1 and 2. (see above)
any suggestions? Thank you
public int ageCalculator(int birthYear, int curYear, int birthMonth, int curMonth, int birthDay, int curDay) { int current = curYear*10000 + curMonth*100 + curDay; int birth = birthYear*10000 + birthMonth*100 + birthDay; return current - birth; //fill in the return statement }