473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Small Calculation Help

H0kage
6
I am Suppose To Create A Program That We Enter A Number Of Seconds Like

95362875

And Return To Me that number in the following way

Years:3
Weeks:1
Days:1
Hours:17
Minutes:41
Seconds:15

Its Suppose To Be In GUI Design which i have already made and its working my problem is the calculations i am suppose to enter in the action performed section of the button.
Dead Line Is Tommorow Morning 9.00am GMT+2

Thank You In Advance
Dec 7 '06 #1
4 1417
I am Suppose To Create A Program That We Enter A Number Of Seconds Like

95362875

And Return To Me that number in the following way

Years:3
Weeks:1
Days:1
Hours:17
Minutes:41
Seconds:15

Its Suppose To Be In GUI Design which i have already made and its working my problem is the calculations i am suppose to enter in the action performed section of the button.
Dead Line Is Tommorow Morning 9.00am GMT+2

Thank You In Advance
normally i wouldn't help as the deadline is so close. but i was bored. The trick is to work out the remainders using modulo (%) and then use a simple division to get the amounts.

hence:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     public void timeConvert(int secs) {
  3. //         int secs = 95362875;
  4.  
  5.         // first set up the constant values for time.
  6.         int YearSecVal = 60 * 60 * 24 * 7 * 52;
  7.         int WeekSecVal = 60 * 60 * 24 * 7;
  8.         int DaySecVal = 60 * 60 * 24;
  9.         int HourSecVal = 60 * 60;
  10.         int MinSecVal = 60;   
  11.  
  12.         // next work out the remainding seconds from each calc.
  13.         int newWeekSecs = secs % YearSecVal;
  14.         int newDaySecs = newWeekSecs % WeekSecVal;
  15.         int newHourSecs = newDaySecs % DaySecVal;
  16.         int newMinSecs = newHourSecs % HourSecVal;
  17.         int newSecs = newMinSecs % MinSecVal;
  18.  
  19.         // print it all out!
  20.         System.out.println(secs / YearSecVal + " years");
  21.         System.out.println(newWeekSecs / WeekSecVal + " weeks");
  22.         System.out.println(newDaySecs / DaySecVal + " days");
  23.         System.out.println(newHourSecs / HourSecVal + " hours");
  24.         System.out.println(newMinSecs / MinSecVal + " mins");
  25.         System.out.println(newSecs + " secs");
  26.  
  27.     }
  28.  
  29.  
and im also hoping your deadline has passed now :|

Theres prob a much nicer recursive way to do this, but simplicity was never a strong point.
Dec 8 '06 #2
H0kage
6
Thank You M8 your help is appreciated.Yup I missed the deadline but at least i will understand its function.
Dec 11 '06 #3
r035198x
13,262 8TB
Thank You M8 your help is appreciated.Yup I missed the deadline but at least i will understand its function.
And hopefully you'll post your problems much earlier too. Sorry you did not get a response on time though. I was away myself at the time.
Dec 11 '06 #4
H0kage
6
Like you say i will try to post earlier but i wanted it to fight it till the last day
before the end since i dont like to get ready solutions.I want Tips and guidance :)
Dec 17 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: aleksander.helgaker | last post by:
I'm learning to program python on my Mac and I'd like some help. I followed a tutorial which showed how to make a calculator for working out the area of a shape. E.g. the area of a circal is...
31
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
2
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that some of the...
1
by: cdelaney | last post by:
I have a form that I created a calculation on using 2003. The calculation works exactly like I want it to but ONLY on the first and last record. The calculation does not work/exist on records in...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
1
by: jlf | last post by:
Need serious help with a calculation. The fields are based on a query that has linked many different tables. The calculation I currently have is: =sum()/((+)*(Piecesnum])) It is giving a...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
3
by: mattmao | last post by:
Okay, I was asked by a friend about the result of this limit: http://bbs.newwise.com/attdata/forumid_14/20070922_fe7f77c81050413a20fbDWYOGm7zeRj3.jpg Not n->zero but n-> + infinite I really...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.