Results 1 to 6 of 6
 02132011, 10:03 PM #1Member
 Join Date
 Feb 2011
 Posts
 11
 Rep Power
 0
So I'm supposed to convert seconds to hours...
I went to class yesterday and the teacher says you should be on each lab for about 30 minutes and you should be done, but it takes me at least 45 hours to get everything together... I'm doubting whether this is right for me...I like working on this but man I take too much time?
having said that, I'm having problems dividing seconds into hours to get it in the standard time format and the am/pm time format. It looks easy, since you divide 60 by the seconds entered to get hours, divide by 60 again to get the minute then again to get seconds...but it comes out weird?
1. Divide the seconds entered by the user by the number of seconds in an hour
(SECONDS_X_HOUR), the result will be the hours in standard time.
2. Compute the remainder of seconds entered by the user by the number of seconds
in an hour (SECONDS_X_HOUR).
3. Divide the remainder obtained in the previous step by the number of seconds in a
minute (SECONDS_X_MINUTE), the result of this division will be the minutes.
4. The remainder of this last division will be the seconds.int SECONDS_X_HOUR = 3600;
int SECONDS_X_MINUTE = 60;
int AM_PERIOD = 43199;
System.out.print("Please enter the time in seconds: ");
long Answer = keyboard.nextLong();
if (Answer < 0){
System.out.println("You must enter a number bigger than 0!");
}
else {
// Standard Format
double standardHour = (Answer / SECONDS_X_HOUR);
double standardMinute = ((standardHour%) /SECONDS_X_MINUTE);
double standardSecond = ((standardMinute%) / SECONDS_X_MINUTE);
System.out.println("Standard Format: " + standardHour + "h., " + standardMinute + "m., " + standardSecond + "s.");
 02132011, 10:08 PM #2Senior Member
 Join Date
 Aug 2010
 Posts
 127
 Rep Power
 0
As far as I know, your only mistake is in the use of the '%'operator, do you know how that operator works, what it does?
 02132011, 10:10 PM #3Member
 Join Date
 Feb 2011
 Posts
 11
 Rep Power
 0
remainder, supposed to take the remainder of the divided number between the x % y, isn't it? also sometimes the answer comes out to be a loooong decimal, thinking about it now I'm not sure if decimals should happen at all... is that right?
ohohhhh i got it thanks I was on this lab for like 4 hours now and was really frustrated :< confused the definition of remainder with the decimal points you get when you divide with like a calculator or somethingLast edited by nope; 02132011 at 10:16 PM.
 02132011, 10:29 PM #4Senior Member
 Join Date
 Jan 2011
 Location
 Belgrade, Serbia
 Posts
 305
 Rep Power
 4
So is it working now?
 02132011, 10:48 PM #5Member
 Join Date
 Feb 2011
 Posts
 11
 Rep Power
 0
At least that part, yes, working on figuring out the AM/PM part now.
Got everything but the last part: The supposed answer should have returned without any decimals, but I see .0 after all the hr/min/sec. I haven't learned about math.round nor BigInteger yet and I vaguely remember %2 or something like that (formatter apparently), how do I set it up so no decimals show? "%.2f" is supposed to be with 1 decimal place, isn't it?Last edited by nope; 02142011 at 12:18 AM.
 02142011, 12:46 AM #6
Similar Threads

Finding epoch seconds and separate yera,month,day,hr,min and seconds
By sathish kumar in forum New To JavaReplies: 4Last Post: 09092010, 11:15 AM 
small method isn't supposed to go under 0
By senca in forum New To JavaReplies: 2Last Post: 08092010, 01:23 PM 
a constructor to convert seconds to hours, min & seconds
By senca in forum New To JavaReplies: 3Last Post: 04052010, 01:08 PM 
Convert microseconds to seconds
By Basit56 in forum New To JavaReplies: 4Last Post: 12312009, 06:54 AM 
Help interpreting what a class is supposed to do
By bornwithnoname in forum New To JavaReplies: 2Last Post: 11202008, 01:19 AM
Bookmarks