Java: Finding birthdate on different planets?

1000 * 60 * 60 * 24 * 365 is actually 31536000000 which is bigger than Integer. MAX_VALUE this causes an overflow. As an integer it would be evaluated to 1471228928 which leads to the wrong result.

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I'm writing a program that asks the user for their birthdate and then calculates that birthdate on different planets. I am not suppose to assume how the birthdate is to be enter except that there is one white space between each number. The code I have right now does not meet these specifications right now and I'm not sure how to write it otherwise.

I am also having problem calculating what my age would be today. When I enter my birthdate and print out age, it currently tells me that I'm 407 yet when I print out dateBirth and today, both of those dates are correct System.out. Print("Please enter your birthdate (mm dd yyyy): "); birthdate = scan.nextLine(); DateFormat df = new SimpleDateFormat("MM dd yyyy"); Date dateBirth = df.

Parse(birthdate); Calendar calBirth = new GregorianCalendar(); calBirth. SetTime(dateBirth); Calendar calDay = new GregorianCalendar(); today = calDay.getTime(); age = (today.getTime() - dateBirth.getTime()) / (1000 * 60 * 60 * 24 * 365); java homework string user-input link|improve this question edited Feb 26 '10 at 17:18Kris5,80311632 asked Feb 26 '10 at 17:06Kat1359 100% accept rate.

Probably, you mean age instead of birthday... For a solution, try replacing with . It's magic! – Fortega Feb 26 '10 at 17:23 Yes, I too am confused.

How is my birthday any different on another planet. – Steve Kuo Feb 26 '10 at 17:37 Why are you using Calendar? – jball Feb 26 '10 at 17:49 You have another problem, in the requirements.

There's no solution for arbitrary date formats in input. For example, if I enter "10 11 12", what date is that? – Hugh Brackett Feb 26 '10 at 17:57.

1000 * 60 * 60 * 24 * 365 is actually 31536000000 which is bigger than Integer. MAX_VALUE this causes an overflow. As an integer it would be evaluated to 1471228928 which leads to the wrong result.

The solution is append the letter L to one of your constants long div = ( 1000 * 60 * 60 * 24 * 365L ); long age = ( today.getTime() - dateBirth.getTime() ) / div.

You beat me in time... – whiskeysierra Feb 26 '10 at 17:23.

You should check if the expression 1000 * 60 * 60 * 24 * 365 evaluates to the result you are expecting and if not, find a way to get the expected result. Perhaps you should even consider that on earth, we have so called leap years and that you could tag your question as homework.

Don't forget the non-integral periods of the other planets. Finding out how the locals deal with it could be problematic, though. – Hugh Brackett Feb 26 '10 at 18:23 Earth is also non-integral.

A year is about 365.24 days – Steve Kuo Feb 26 '10 at 20:02.

1000 * 60 * 60 * 24 * 365 Is an int, but its to long to hold it. Make one of these a long, like: 1000L * 60 * 60 * 24 * 365.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions