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:
-
-
public void timeConvert(int secs) {
-
// int secs = 95362875;
-
-
// first set up the constant values for time.
-
int YearSecVal = 60 * 60 * 24 * 7 * 52;
-
int WeekSecVal = 60 * 60 * 24 * 7;
-
int DaySecVal = 60 * 60 * 24;
-
int HourSecVal = 60 * 60;
-
int MinSecVal = 60;
-
-
// next work out the remainding seconds from each calc.
-
int newWeekSecs = secs % YearSecVal;
-
int newDaySecs = newWeekSecs % WeekSecVal;
-
int newHourSecs = newDaySecs % DaySecVal;
-
int newMinSecs = newHourSecs % HourSecVal;
-
int newSecs = newMinSecs % MinSecVal;
-
-
// print it all out!
-
System.out.println(secs / YearSecVal + " years");
-
System.out.println(newWeekSecs / WeekSecVal + " weeks");
-
System.out.println(newDaySecs / DaySecVal + " days");
-
System.out.println(newHourSecs / HourSecVal + " hours");
-
System.out.println(newMinSecs / MinSecVal + " mins");
-
System.out.println(newSecs + " secs");
-
-
}
-
-
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.