Results 1 to 13 of 13
Thread: Anyone good at math?
- 01-02-2009, 05:37 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 30
- Rep Power
- 0
Anyone good at math?
I have a program to do, and i figured that since i have the code working properly, i shouldn't post it in the new to java section..
anyways..
we are supposed to get the current date, and get the date of which the user was born on and the program is supposed to tell the user how many DAYS they have lived and the hours they have slept.
we are told to make years=365 days, months=30 days.
and we also assume they sleep 8 hours a night (but that part is easy, just multiply the days by 8)
anyone good at math who knows how to get this?
my code doesnt really need any editing, so theres no need to post it..
i just suck at math xD
- 01-02-2009, 05:50 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you want to do exactly. Convert the date into days?
- 01-02-2009, 06:07 AM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
you can use calendar class
create 2 calendar object, one for instant, one for the inputted date
and use functions like cal.get(cal.YEAR) to calulate
year diff, month diff, and day diff
- 01-02-2009, 06:27 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 30
- Rep Power
- 0
Hm, we havent really learned about that yet,
is there any other way?
And yes, I want to convert the date to days
- 01-02-2009, 06:55 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you are using that assumptions why it's difficult? I mean you have two dates something like this, 1980/10/23 and the current date. So you have to deduct from each other.
But you have to validate few cases before doing deduct. Days must be greater than 30, month must be greater than 12.
But it's not easy to write in to the code. Use if the Calender is much effective.
- 01-02-2009, 07:04 AM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
learnt?....
then do you know Date class and SimpleDateFormat?
Construct new Date object
use format method in SimpleDateFormat to format it...
do you know String class
use parse method to get current year, month, date...
compute the year/month/day diffLast edited by mtyoung; 01-02-2009 at 07:19 AM.
- 01-02-2009, 07:56 PM #7
Member
- Join Date
- Nov 2008
- Posts
- 30
- Rep Power
- 0
ultimately, all i want help with is the MATH,
im not strong in math so i want to know how to get the differences of the years?
without talking about java, i just want to know the method of how to obtain the # of days someone has been alive for given the current date and the date they were born..
something like add this, subtract that..kind of thing
- 01-03-2009, 01:33 AM #8
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
assume the format of date is yyyy/MM/dd
current date is 2009/01/03 and DOB is 1957/09/13
then
diff is current - DOB
let consider month case
1 - 9 = -8
because of 1 year = 12 months
difference in month is 1 - 9 + 12 = 4
and so on...
- 01-03-2009, 04:01 AM #9
Member
- Join Date
- Nov 2008
- Posts
- 30
- Rep Power
- 0
so, from the 4, how do i get the amount of days someone has lived?
- 01-03-2009, 04:06 AM #10
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
if diff is 3 year, 4 month, 10 dayswe are told to make years=365 days, months=30 days. sleep 8 hours a night
(3 * 365 + 4 * 30 + 10) * 8
remind carry in calculationLast edited by mtyoung; 01-03-2009 at 04:14 AM.
- 01-03-2009, 10:37 AM #11
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
8 more hours may needed
as 14/10/2008, 16/10/2008 diff in 2 days
but 14, 15 and 16 are 3 days
- 01-08-2009, 08:35 AM #12
I have a degree in Mathematics. You are not asking about math, maybe arithmetic, but really you just need to learn how to use the APIs for the date classes. or look at JodaDates.
The Java Date classes from Java 1.0 leave a lot to be desired. They have been patched and improved a little, but still are pretty inconsistent.
- 01-11-2009, 04:12 PM #13
yep,,...it says to use Calander class.
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Similar Threads
-
Hello Good Morning, Good afternoon, and Good Evening
By MrFreeweed in forum IntroductionsReplies: 3Last Post: 12-11-2009, 03:32 PM -
Which framework is good?
By felixtfelix in forum Web FrameworksReplies: 6Last Post: 08-16-2008, 12:48 AM -
Any Good e-book in JSF
By felixtfelix in forum Web FrameworksReplies: 0Last Post: 05-08-2008, 05:18 PM -
any good java magazines around
By dubdubdub in forum New To JavaReplies: 18Last Post: 01-17-2008, 06:26 PM -
i'm no good in calling Method please help
By lowpro in forum New To JavaReplies: 1Last Post: 11-26-2007, 05:15 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks